Jump to content

Vigenère cipher: Difference between revisions

→‎{{header|AutoHotkey}}: shortened Decipher routine by taking advantage of the trick posted in talk page
(→‎{{header|AutoHotkey}}: shortened Decipher routine by taking advantage of the trick posted in talk page)
Line 174:
 
VigenereDecipher(Text, key){
Loop Parse, Textkey
decoderKey .= Chr(26-(Asc(A_LoopField)-65)+65)
{
return VigenereCipher(Text, decoderKey)
a := Asc(A_LoopField) - Asc("A")
b := Asc(SubStr(Key, 1+Mod(A_Index-1, StrLen(Key)), 1)) - Asc("A")
if (a-b) < 0
n := 26-(b-a)
else n := a-b
out .= Chr(Mod(n,26)+Asc("A"))
}
return out
}</lang>
Output:
Line 190 ⟶ 183:
Ciphertext =WMCEEIKLGRPIFVMEUGXQPWQVIOIAVEYXUEKFKBTALVXTGAFXYEVKPAGY
Decrypted =BEWARETHEJABBERWOCKMYSONTHEJAWSTHATBITETHECLAWSTHATCATCH</pre>
 
=={{header|C}}==
<lang C>#include <stdio.h>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.