-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPuzzleTools.livecodescript
More file actions
55 lines (49 loc) · 1.49 KB
/
PuzzleTools.livecodescript
File metadata and controls
55 lines (49 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
script "PuzzleToolsLib"
function toNumber pChar
local tNum
put chartonum(toUpper(pChar)) - 64 into tNum
if tNum < 1 or tNum > 26 then
throw "char not in the range A to Z"
else
return tNum
end if
end toNumber
function fromNumber pNum
local tNum
put ((pNum - 1) mod 26) + 65 into tNum
return numtochar(tNum)
end fromNumber
function caesarShift pTarget, pAmount
local tOutput
if pAmount is not a number then
put toNumber(pAmount) - 1 into pAmount
end if
repeat for each char tChar in pTarget
put fromNumber(toNumber(tChar) + pAmount) after tOutput
end repeat
return tOutput
end caesarShift
function vigenereShift pTarget, pCipher
local tOutput, tCipherSize, tCount
put the number of chars of pCipher into tCipherSize
repeat for each char tChar in pTarget
add 1 to tCount
put caesarShift(tChar, char (((tCount - 1) mod tCipherSize)+1) of pCipher) after tOutput
end repeat
return tOutput
end vigenereShift
function caesarDecode pTarget, pAmount
if pAmount is not a number then
put toNumber(pAmount) - 1 into pAmount
end if
return caesarShift(pTarget, 26 - pAmount)
end caesarDecode
function vigenereDecode pTarget, pKey
local tOutput, tKeySize, tCount
put the number of chars of pKey into tKeySize
repeat for each char tChar in pTarget
add 1 to tCount
put tOutput & caesarDecode(tChar, char (((tCount) mod tKeySize)+1) of pKey) into tOutput
end repeat
return tOutput
end vigenereDecode