string SolitaireCrypto::decrypt() { if (keystream.length() != ciphertext.length()) { cleartext.assign(""); return ""; } string output(""); char keywork; char cipherwork; char outwork; for(unsigned int i=0; i<keystream.length(); i++) { keywork=charCodeAt(keystream[i]); keywork=(keywork-64)%26; cipherwork=charCodeAt(ciphertext[i]); cipherwork=(cipherwork-64)%26; outwork=(cipherwork-keywork)%26; if(outwork<0) {outwork=26+outwork;} outwork=outwork+64; if(outwork==64) {outwork=90;} output += fromCharCode(outwork); } cleartext.assign(output); return output; }
string SolitaireCrypto::encrypt() { if (keystream.length() != cleartext.length()) { ciphertext.assign(""); return ""; } string output(""); char keywork; char clearwork; char outwork; for(unsigned int i=0; i<keystream.length(); i++) { keywork=charCodeAt(keystream[i]); keywork=(keywork-64)%26; clearwork=charCodeAt(cleartext[i]); if(clearwork>=65&&clearwork<=90) {clearwork=(clearwork-64)%26;} if(clearwork>=97&&clearwork<=122) {clearwork=(clearwork-96)%26;} outwork=(clearwork+keywork)%26; outwork=outwork+64; if(outwork==64) {outwork=90;} output += fromCharCode(outwork); } ciphertext.assign(output); return output; }
CompletionType evaluate() { Register<Value> value; switch (method) { case FromCharCode: value = fromCharCode(); break; } return CompletionType(CompletionType::Return, value, ""); }
void SolitaireCrypto::keygen(unsigned int msgLen) { keystream.assign(""); for(unsigned int k=0; k< msgLen; k++) { solitaire(); if(output()<53) { keystream += fromCharCode(((output()-1)%26)+65); } if(output()>=53) { k--; } } }