This program uses the Vigenere polyalphabet method.
It is much harder to break than a simple Caesar shift.
If anyone has any ideas how to improve it, I would be pleased to hear them.
Geoff.
REM A program to encipher and decipher the
REM contents of a text file.
`*********************************************************
`Before running this program:- *
`1) Use Microsoft Notepad to create your plaintext message. *
`For example:-
`MEET ME TONIGHT
`IN THE YARD
`AT MIDNIGHT
`(use only uppercase letters, with no punctuation)
`2) Create a new program in DB *
`3) Name your Notepad file - Dark.txt - and save it into *
`the folder you created for the DB project. *
`**********************************************************
Dim Alpha(26, 4)
Global text$
Global bytesNum
bytesNum = File Size("Dark.txt")
ReadTheFile()
Print "THE CONTENTS OF THE FILE:-"
Print
Print text$
Print
Print
Print
Input "Enter e to encipher, or r to recover the message:- (To leave, press Esc)"; choice$
If choice$ = "e" Then Encipher()
If choice$ = "r" Then Recover()
Wait Key
End
Function ReadTheFile()
Open To Read 1,"Dark.txt"
While File End(1) = 0
Read String 1,var$
text$ = text$ + var$ + Chr$(10) + Chr$(13)
EndWhile
Close File 1
EndFunction
Function Encipher()
Cls
Print "Please be patient......"
InitialiseArray(10,4,24) `code word = KEY
ChangeFile()
ReadTheFile()
Cls
Print "The message in the file has now been enciphered"
Print "Press Esc to leave."
EndFunction
Function Recover()
Cls
Print "Please be patient......"
InitialiseArray(16,22,2)
ChangeFile()
ReadTheFile()
Cls
Print "The message in the file has now been recovered"
Print "Press Esc to leave."
EndFunction
Function Cipher(char, offset)
If char + offset <= 90 `Cipher is <= "Z"
Cipher = char + offset
Else `Cipher is > "Z", so cycle around
Cipher = char + offset - 26
EndIf
EndFunction Cipher
Function InitialiseArray(K, E, Y)
For row = 1 To 26
letter = row + 64
Alpha(row, 1) = letter
Alpha(row, 2) = Cipher(letter, K)
Alpha(row, 3) = Cipher(letter, E)
Alpha(row, 4) = Cipher(letter, Y)
Next row
EndFunction
Function ChangeFile()
col = 2
For pos = 0 To bytesNum-1
row = 0
bit = Read Byte From File("Dark.txt",pos)
If bit = 32
pos = pos + 1
bit = Read Byte From File("Dark.txt",pos)
EndIf
If bit <14 And bit >9
pos = pos + 2
bit = Read Byte From File("Dark.txt",pos)
EndIf
Repeat
row = row + 1
check = Alpha(row,1)
Until bit = check
Write Byte To File "Dark.txt",pos,Alpha(row,col)
col = col + 1
If col >4 Then col = 2
Next pos
EndFunction