Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- unsigned int Hash(const char * str)
- {
- unsigned int hash = 0;
- for(; *str; str++)
- {
- hash += (unsigned char)(str);
- hash -= (hash << 13) | (hash >> 19);
- }
- return hash;
- }
- int main(void)
- {
- char KeyWord[255], Plain[255], Enc[255], DecTemp[255];
- int i=0, ii=0, KeyLength=0, PlainLength=0, EncLength=0, DecLength=0;
- printf("Enter key: ");
- gets(KeyWord);
- while(KeyWord[KeyLength])
- KeyLength++;
- unsigned int HashedKey[KeyLength];
- for (i = 0; i<KeyLength; i++)
- HashedKey[i] = Hash(&KeyWord[i]);
- printf("Enter message: ");
- gets(Plain);
- while(Plain[PlainLength])
- PlainLength++;
- for (i=0; i<PlainLength; i++)
- {
- Enc[i] = Plain[i]^HashedKey[ii];
- EncLength++;
- if (ii<KeyLength)
- ii++;
- else
- ii=0;
- }
- printf("!!! ii = %d\n", ii);
- ii=0;
- for (i=0; i<EncLength; i++)
- {
- DecTemp[i] = Enc[i]^HashedKey[ii];
- DecLength++;
- if (ii<KeyLength)
- ii++;
- else
- ii=0;
- }
- printf("!!! ii = %d\n", ii);
- //char Decrypted[DecLength];
- //for(i=0; i<DecLength; i++)
- // Decrypted[i] = DecTemp[i];
- printf("KEY: %s\n\nPLAINTEXT: %s\n\nKEYHASH: ", KeyWord, Plain);
- for (i=0; i<KeyLength; i++)
- printf("%X ", HashedKey[i]);
- printf("\n\nENCRYPTEDTEXT: %s\n\nDECRYPTEDTEXT: %s", Enc, DecTemp);
- printf("\n\nKEYLENGTH: %d\n\nPLAINLENGTH: %d\n\nENCLENGTH: %d\n\nDECLENGTH: %d\n\n", KeyLength, PlainLength, EncLength, DecLength);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement