Vigenère cipher: Difference between revisions

Content added Content deleted
(→‎{{header|AutoHotkey}}: shortened Decipher routine by taking advantage of the trick posted in talk page)
Line 174: Line 174:


VigenereDecipher(Text, key){
VigenereDecipher(Text, key){
Loop Parse, Text
Loop Parse, key
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>
}</lang>
Output:
Output:
Line 190: Line 183:
Ciphertext =WMCEEIKLGRPIFVMEUGXQPWQVIOIAVEYXUEKFKBTALVXTGAFXYEVKPAGY
Ciphertext =WMCEEIKLGRPIFVMEUGXQPWQVIOIAVEYXUEKFKBTALVXTGAFXYEVKPAGY
Decrypted =BEWARETHEJABBERWOCKMYSONTHEJAWSTHATBITETHECLAWSTHATCATCH</pre>
Decrypted =BEWARETHEJABBERWOCKMYSONTHEJAWSTHATBITETHECLAWSTHATCATCH</pre>

=={{header|C}}==
=={{header|C}}==
<lang C>#include <stdio.h>
<lang C>#include <stdio.h>