BTC USD 85,877.3 Gold USD 4,339.13
Time now: Jun 1, 12:00 AM

kepada pakar programming! dah wat, tapi ada error.. help!

giant.1989

Super Active Member
Messages
5,467
Paid Membership
Joined
Jan 15, 2011
Messages
5,467
Reaction score
34
Points
70
salam.. harap ada yg dapat bantu...
ni masalah die.. nak ubah string to ascii.. kena wat encrypt ngan decrypt.. tapi die dah bagi code untuk decrypt ngan decrypt..

aku dah wat, tp de masalah plak..harap de yg dapat tolong..
ni task aku...

1. Software function development:
a. Read an arbitrary length of message string and a fixed length of key string from user input to
arrays of ASCII-coded form. Example: message string: “abcdefgh”
ASCII-coded form in hexadecimal: A[0] = 0x61626364, A[1] = 0x65666768
b. Develop TEA software functions (software TEA) which can compute the message
encryption to generate ciphertext, and compute decryption to recover original plaintext,
respectively.
c. Display the encryption/decryption output on the terminal screen in both hexadecimal and
character modes.

ni plak code yang mesti ada dalam program aku....
Encryption / Encode:
void code(long* v, long* k)
{
unsigned long y=v[0],z=v[1], sum=0, /* set up */
delta=0x9e3779b9, /* a key schedule constant */
for i = 0 to 31 /* basic cycle start */
sum += delta ;
y += ((z<<4)+k[0]) ^ (z+sum) ^ ((z>>5)+k[1]) ;
z += ((y<<4)+k[2]) ^ (y+sum) ^ ((y>>5)+k[3]) ;
end for
v[0]=y ; v[1]=z ;
}
Decryption / decode:
void decode(long* v,long* k)
{
unsigned long y=v[0], z=v[1], sum;
delta=0x9e3779b9 ;
sum=delta<<5 ;
for i = 0 to 31 /* basic cycle start */
z-= ((y<<4)+k[2]) ^ (y+sum) ^ ((y>>5)+k[3]) ;
y-= ((z<<4)+k[0]) ^ (z+sum) ^ ((z>>5)+k[1]) ;
sum-=delta ;
end for
v[0]=y ; v[1]=z ;
}


#include <iostream>
#include <string>
#include <ctype>

//using namespace std;

void code(unsigned long *v, unsigned long *k)
{
unsigned long y = v[0],z = v[1],sum = 0,
delta = 0x9e3779b9;
short int i;
for(i=0;i<=31;i++)
{
sum += delta;
y += ((z<<4)+k[0]) ^ (z+sum) ^ ((z>>5)+k[1]) ;
z += ((y<<4)+k[2]) ^ (y+sum) ^ ((y>>5)+k[3]) ;
}
v[0] = y;
v[1] = z;

}

void decode(unsigned long *v, unsigned long *k )
{
unsigned long y = v[0],z=v[1],sum,
delta = 0x9e3779b9;
short int i;
sum = delta << 5;
for(i=0;i<=31;i++)
{
z -= ((y<<4)+k[2]) ^ (y+sum) ^ ((y>>5)+k[3]) ;
y -= ((z<<4)+k[0]) ^ (z+sum) ^ ((z>>5)+k[1]) ;
sum -= delta; 
}

v[0] = y;
v[1] = z;
}
int main()
{
int dummy;
unsigned long *a;
unsigned long key;


cout << "These program will encript your words.\nPlease enter a valid sentence (with spaces):\n>";
cin >> a;
cout << "You have entered: " << a << endl << endl;
cout << "Please insert your password to lock your words.\n"<< endl;
cin >> key;
code(a,&key);
cout << "Your words successfully encrypted." << endl << "this is your encrypted words looks like: "<< endl;
cout << key << endl << endl << endl;
key = 0;
cout << "==================" << endl;
cout << "Decrypt your words" << endl;
cout << "==================" << endl << endl;
cout << "Kindly insert your password to retrieve your words: ";
cin >> key;
decode(a,&key);
cout << "Your words is :"<< a << "if you enter a correct password"<< endl;
cin >> dummy;
}

ok.. harap2, sape2 boleh tolong.. tqvm..
 
Back
Top
Log in Register