Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// 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
- function vigenere_ascii($in, $key, $mode)
- {
- $out = "";
- $inLen = strlen($in);
- $keyLen = strlen($key);
- $loVal = 32;
- $hiVal = 126;
- $span = ($hiVal - $loVal) + 1;
- for ($pos=0; $pos<$inLen; $pos+=1) {
- $inChar = substr($in, $pos, 1);
- $keyChar = substr($key, $pos % $keyLen, 1);
- $inVal = min(max($loVal, ord($inChar)), $hiVal) - $loVal;
- $keyVal = min(max($loVal, ord($keyChar)), $hiVal) - $loVal;
- if ($mode) {
- $outVal = (($inVal + $keyVal) % $span) + $loVal;
- }else{
- $outVal = (($span + $inVal - $keyVal) % $span) + $loVal;
- }
- $outChar = chr($outVal);
- $out = $out . $outChar;
- }
- return $out;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement