We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
some help - part one
#3
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
Reply


Messages In This Thread
some help - part one - by Yumda - 03-21-2025, 07:49 AM
RE: some help - part one - by Yumda - 03-21-2025, 07:50 AM
RE: some help - part one - by Yumda - 03-21-2025, 07:50 AM
RE: some help - part one - by z-s - 03-21-2025, 09:02 AM
RE: some help - part one - by Yumda - 03-21-2025, 10:35 AM
RE: some help - part one - by AbsoluteBeginner - 03-21-2025, 12:21 PM
RE: some help - part one - by litdev - 03-21-2025, 02:41 PM
RE: some help - part one - by Yumda - 03-22-2025, 09:16 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)