Caesar Cipher Function
Caesar Cipher Function
Is the Caesar cipher function a legacy one or not? It's not working for me in my script!
Re: Caesar Cipher Function
It's not a built-in function, so you should tell potential helpers about which function (version) we are talking... code and/or link would help.
You should also add how you called it.
You should also add how you called it.
Re: Caesar Cipher Function
Oh, ok...
Here's my encrypt code:
But I've also tried this one:
Thanks!
Here's my encrypt code:
Code: Select all
vText := "mastpass"
vmastencrypted := ""
Loop, 26
{
vIndex := A_Index-1
Loop, Parse, vText
{
vNum := Ord(A_LoopField)
if (vNum >= 65) && (vNum <= 90)
vmastencrypted .= Chr(Mod(vNum-65+vIndex, 26)+65)
else if (vNum >= 97) && (vNum <= 122)
vmastencrypted .= Chr(Mod(vNum-97+vIndex, 26)+97)
else
vmastencrypted .= A_LoopField
}
vmastencrypted .= "`r`n"
}
MsgBox, % vOutput
Code: Select all
mastencrypted := caesarCipher(%mastpass%, 8, key)
Re: Caesar Cipher Function
Without even running this, a few questions arise...
Where does vOutput in MsgBox, % vOutput come from? You never assign anything to it... perhaps you meant to display vmastencrypted instead.
Try MsgBox, % vmastencrypted
Where is the user-defined function caesarCipher() ? AHK doesn't know this function, if you don't provide it.
btw, variables in the parameter section of a function are rarely surrounded by %s - only if you want to do a double-deref... but if it's supposed to be a literal string, you should quote it.
Where does vOutput in MsgBox, % vOutput come from? You never assign anything to it... perhaps you meant to display vmastencrypted instead.
Try MsgBox, % vmastencrypted
Where is the user-defined function caesarCipher() ? AHK doesn't know this function, if you don't provide it.
btw, variables in the parameter section of a function are rarely surrounded by %s - only if you want to do a double-deref... but if it's supposed to be a literal string, you should quote it.
Re: Caesar Cipher Function
Oh yeah, I see that the variable Output is meant to be mastencrypted. I'll try that, and I didn't know that variables in the parameter section of a function are rarely surrounded by %.
Also, what do you mean by
Also, what do you mean by
I'm still very much a beginner here!Where is the user-defined function caesarCipher() ? AHK doesn't know this function, if you don't provide it.
Re: Caesar Cipher Function
Well, like I said. caesarCipher() is not a built-in function. AHK doesn't know it, if you don't provide it.
You can define functions yourself (<-- please follow the link, and read about functions) by putting them into your script, or copypaste functions made by others. Then you can call them.
A simple user-defined function, and a function call:
You can define functions yourself (<-- please follow the link, and read about functions) by putting them into your script, or copypaste functions made by others. Then you can call them.
A simple user-defined function, and a function call:
Code: Select all
say("hello") ; function call
say(var) { ; function definition
msgbox % var
}
- flyingDman
- Posts: 2817
- Joined: 29 Sep 2013, 19:01
Re: Caesar Cipher Function
This is probably the function that @Ben G is referring to: https://www.autohotkey.com/board/topic/82506-function-caesar-cipher/
In its simplest form:
The bigger question is, why even use it. It provides very little protection and there are much more secure ways to encrypt strings. for instance:
viewtopic.php?f=6&t=23413
In its simplest form:
Code: Select all
msgbox % z := caesarCipher("abcde", 8)
msgbox % caesarCipher(z, -8)
caesarCipher(text, shift, key = "abcdefghijklmnopqrstuvwxyz"){
Loop, Parse, text
encryptedString .= SubStr(key, Mod(Instr(key, A_LoopField, True) + shift, StrLen(key)), 1)
return encryptedString
}
viewtopic.php?f=6&t=23413
14.3 & 1.3.7