Part 3 of the codes:
Code:
decryptMode:
CRLF = Text.GetCharacter(13) + Text.GetCharacter(10)
TextWindow.WriteLine("Paste the full converted cipher text below (end with ENTER):")
encryptedText = TextWindow.Read()
sessionMapPath = File.ReadLine("p:\cipherwheel\last_session.txt", 1)
For i = 1 To 52
line = File.ReadLine(sessionMapPath, i)
p1 = Text.GetIndexOf(line, "|")
p2 = Text.GetIndexOf(Text.GetSubTextToEnd(line, p1 + 1), "|") + p1
letter = Text.GetSubText(line, 1, p1 - 1)
filePath = Text.GetSubText(line, p1 + 1, p2 - p1 - 1)
lineNum = Text.GetSubTextToEnd(line, p2 + 1)
word = File.ReadLine(filePath, lineNum)
reverseCipher[word] = letter
EndFor
segments = ""
index = 1
While Text.GetLength(encryptedText) > 0
pos = Text.GetIndexOf(encryptedText, "空")
If pos > 0 Then
part = Text.GetSubText(encryptedText, 1, pos - 1)
encryptedText = Text.GetSubTextToEnd(encryptedText, pos + 1)
Else
part = encryptedText
encryptedText = ""
EndIf
segments[index] = part
index = index + 1
EndWhile
originalText = ""
For i = 1 To Array.GetItemCount(segments)
word = segments[i]
If word = "" Then
originalText = originalText + " "
ElseIf reverseCipher[word] <> "" Then
originalText = originalText + reverseCipher[word]
Else
originalText = originalText + "?"
EndIf
EndFor
TextWindow.WriteLine("")
TextWindow.WriteLine("==== DECRYPTION RESULT ====")
TextWindow.WriteLine("Decoded: " + originalText)
Sub InitializeAlphabet
For i = 1 To 26
alphabet[i] = Text.GetCharacterCode(Text.GetSubText("ABCDEFGHIJKLMNOPQRSTUVWXYZ", i, 1))
EndFor
For i = 27 To 52
alphabet[i] = Text.GetCharacterCode(Text.GetSubText("abcdefghijklmnopqrstuvwxyz", i - 26, 1))
EndFor
EndSub
Sub GenerateTimestamp
now = Clock.Date + " " + Clock.Time
newTime = ""
For i = 1 To Text.GetLength(now)
ch = Text.GetSubText(now, i, 1)
If ch = "/" Or ch = ":" Then
newTime = newTime + "-"
ElseIf ch = " " Then
newTime = newTime + "_"
Else
newTime = newTime + ch
EndIf
EndFor
now = newTime
EndSub
Sub EncryptText
convertedText = ""
For i = 1 To Text.GetLength(texttoconvert)
char = Text.GetSubText(texttoconvert, i, 1)
charCode = Text.GetCharacterCode(char)
If char = " " Then
convertedText = convertedText + spaceReplacement
ElseIf newcipheralpha[charCode] <> "" Then
convertedText = convertedText + newcipheralpha[charCode] + "空"
Else
convertedText = convertedText + char + "空"
EndIf
EndFor
convertedText = Text.GetSubText(convertedText, 1, Text.GetLength(convertedText) - 1)
EndSub
Sub DecryptText
segments = ""
index = 1
While Text.GetLength(encryptedText) > 0
pos = Text.GetIndexOf(encryptedText, "空")
If pos > 0 Then
part = Text.GetSubText(encryptedText, 1, pos - 1)
encryptedText = Text.GetSubTextToEnd(encryptedText, pos + 1)
Else
part = encryptedText
encryptedText = ""
EndIf
segments[index] = part
index = index + 1
EndWhile
originalText = ""
For i = 1 To Array.GetItemCount(segments)
word = segments[i]
If word = "" Then
originalText = originalText + " "
ElseIf reverseCipher[word] <> "" Then
originalText = originalText + reverseCipher[word]
Else
originalText = originalText + "?"
EndIf
EndFor
EndSub