I need to implement a Rc4 algorithm with a seed: 1 2 3 6 and the plain text cryptology. I am following this guideline we were provided in class, but it's not initializing S correctly. 
My code was previously printing negative values , not sure why but I managed to fix that error. Thought everything was good to go but it's not. Sorry for the pictures, I figured it was easier to explain what I was following for my code structure. I am mod 4 the seed since it contains 4 characters, could that possibly be my error?
#include <iostream> #include <string> #include <string.h> using std::endl; using std::string; void swap(unsigned int *x, unsigned int *y); int main() { string plaintext = "cryptology"; char cipherText[256] = { ' ' }; unsigned int S[256] = { 0 }; unsigned int t[256] = { 0 }; unsigned int seed[4] = { 1, 2, 3, 6 }; // seed used for test case 1 unsigned int temp = 0; int runningTotal = 0; unsigned int key = 0; // inilializing s and t for (int i = 0; i < 256; i++) { S[i] = i; t[i] = seed[i % 4]; } for (int i = 0; i < 256; i++) { runningTotal += S[i] + t[i]; runningTotal %= 256; swap(&S[runningTotal], &S[i]); std::cout << S[i] <<" "; } runningTotal = 0; for (int i = 0; i < plaintext.size(); i++) { runningTotal %= 256; swap(&S[i], &S[runningTotal]); temp = (unsigned int)S[i] + (unsigned int)S[runningTotal]; temp %= 256; key = S[temp]; std::cout << endl; cipherText[i] = plaintext[i] ^ key; } std::cout << " this is cipher text " << endl; std::cout << cipherText << endl; system("pause"); return 0; } void swap(unsigned int *x, unsigned int *y) { unsigned int temp = 0; temp = *x; *x = *y; *y = temp; } 
