Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vigenere Cipher being incorrect #33

Open
GameEntity903 opened this issue Dec 27, 2022 · 3 comments
Open

Vigenere Cipher being incorrect #33

GameEntity903 opened this issue Dec 27, 2022 · 3 comments

Comments

@GameEntity903
Copy link

GameEntity903 commented Dec 27, 2022

LC_VigenereCipher("Testingabc","Lemon") gives a result of "EOKNBYQSVV" which is supposed to be "Eiehvykmpp" and using LC_VigenereDecipher(LC_VigenereCipher("Testingabc","Lemon"),"Lemon") gives a result of "TE9:/NGABC" which is supposed to be "Testingabc" in the ideal scenario, but since there is an error somewhere in the encrypting process, the output should be "TKYZONMGHI" when the Input to the decipher function is "EOKNBYQSVV".
https://ciphereditor.com/ to verify

@GameEntity903
Copy link
Author

GameEntity903 commented Dec 28, 2022

Alternate function to your function. It's not as concise as yours but it has 2 advantages, 1) Maintaining case, 2) Keeping non-alphabet (ASCII 65-90 & 97-122) characters.

Vigenere2Enc(Key,Input) ;GameNtt
{
key2 := ""
Loop, Parse, Key
if((((Asc(A_LoopField)) >= 65) && ((Asc(A_LoopField)) <= 90)) || (((Asc(A_LoopField)) >= 97) && ((Asc(A_LoopField)) <= 122)))
key2 .= A_LoopField
count := 1
Loop, Parse, Input
{
chint := Asc(SubStr(key2, Mod(A_index, StrLen(key2)),1)) - 65
chint2 := Asc(A_LoopField)
if((((chint >= 0) && (chint <= 25)) || ((chint >= 32) && chint <= 57)) && ((((chint2) >= 65) && ((chint2) <= 90)) || (((chint2) >= 97) && ((chint2) <= 122))))
{
if((chint >= 0) && (chint <= 25))
{
output .= CaesarShift(chint,SubStr(Input, count, 1))
count++
}
Else
{
output .= CaesarShift(chint-32,SubStr(Input, count, 1))
count++
}
}
else
{
output .= A_LoopField
OutputDebug, % A_LoopField " " output
}
}
return output
}

Vigenere2Dec(Key,Input) ;GameNtt
{
key2 := ""
Loop, Parse, Key
if((((Asc(A_LoopField)) >= 65) && ((Asc(A_LoopField)) <= 90)) || (((Asc(A_LoopField)) >= 97) && ((Asc(A_LoopField)) <= 122)))
key2 .= A_LoopField
count := 1
Loop, Parse, Input
{
chint := Asc(SubStr(key2, Mod(A_index, StrLen(key2)),1)) - 65
chint2 := Asc(A_LoopField)
if((((chint >= 0) && (chint <= 25)) || ((chint >= 32) && chint <= 57)) && ((((chint2) >= 65) && ((chint2) <= 90)) || (((chint2) >= 97) && ((chint2) <= 122))))
{
if((chint >= 0) && (chint <= 25))
{
output .= CaesarShift(-(chint),SubStr(Input, count, 1))
count++
}
Else
{
output .= CaesarShift(-(chint-32),SubStr(Input, count, 1))
count++
}
}
else
{
output .= A_LoopField
OutputDebug, % A_LoopField " " output
}
}
return output
}

@GameEntity903
Copy link
Author

Even my function has an error while trying to minimize the length of the function. Well, I'll fix it and update it in a while.

@joedf
Copy link
Member

joedf commented Jan 21, 2023

Thanks for sharing, please feel free to submit a pull request if you have a fix. Update the test cases if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants