Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- const int alphaLength = 26;
- char* vizhiner(char* str, const char* key, int mode)
- {
- char* origStr = str;
- size_t keyLength = strlen(key);
- int keyPos = 0;
- while (*str)
- {
- if (mode)
- {
- *str++ = ('A' + (*str + *(key + keyPos)) % alphaLength);
- }
- else
- {
- *str++ = ('A' + (*str + alphaLength - *(key + keyPos)) % alphaLength);
- }
- // *str++ = ('A' + (*str + (mode ? *(key + keyPos++) : alphaLength - *(key + keyPos++))) % alphaLength);
- ++keyPos;
- keyPos %= keyLength;
- }
- return origStr;
- }
- int main()
- {//
- char str[] = { "ATTACKATDAWN" };
- char key[] = { "LEMON" };
- printf("Original:\t%s\n", str);
- printf("Encoded:\t%s\n", vizhiner(str, key, 1));
- printf("Decoded:\t%s\n", vizhiner(str, key, 0));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement