vigenere_ascii
This is based on the classic Vigenère cipher. Using a repeating key, the letters in the target text are shifted in the alphabet by varying amounts. While effective, this is not a strong encryption. A determined person would likely be able to crack it. The cipher becomes more effective as the length of the key increases. The biggest weakness with Vigenère ciphers is in cases where many spaces or zero-value characters exist in the source data. When that happens the enciphering key can be exposed. Using long keys which appear random can help hide the exposure.
G A M E M A K E R 7 1 13 5 13 1 11 5 18
K E Y K E Y K E Y 11 5 25 11 5 25 11 5 25
- - - - - - - - - -- -- -- -- -- -- -- -- --
R F L P R Z V J Q 18 6 12 16 18 26 22 10 17
- vigenere_ascii(in,key,mode)
- Returns the given string enciphered or deciphered using a simple Vigenere style cipher, and filtering out non-printable characters.
COPY/// vigenere_ascii(in,key,mode)
//
// Returns the given string enciphered or deciphered
// using a simple Vigenere style cipher, and filtering
// out non-printable characters.
//
// in input, string
// key enciphering key, string
// mode 0 = decipher, 1 = encipher
//
/// GMLscripts.com/license
{
var in, key, mode, out;
in = argument0;
key = argument1;
mode = argument2;
out = "";
var inLen, keyLen, pos, inChar, keyChar, outChar;
var inVal, keyVal, outVal, loVal, hiVal, span;
inLen = string_length(in);
keyLen = string_length(key);
loVal = 32;
hiVal = 126;
span = (hiVal - loVal) + 1;
for (pos=0; pos<inLen; pos+=1) {
inChar = string_char_at(in, pos+1);
keyChar = string_char_at(key, (pos mod keyLen)+1);
inVal = min(max(loVal, ord(inChar)), hiVal) - loVal;
keyVal = min(max(loVal, ord(keyChar)), hiVal) - loVal;
if (mode) {
outVal = ((inVal + keyVal) mod span) + loVal;
}else{
outVal = ((span + inVal - keyVal) mod span) + loVal;
}
outChar = chr(outVal);
out = out + outChar;
}
return out;
}
Contributors: xot
GitHub: View · Commits · Blame · Raw