I had the opportunity to concentrate on something I wanted to code ever since I learned of programming. The fond memory of how my mom amazed me with her stories when I was then a kid regarding espionage, the CIA, military and terrorism urged me to divert some time on this effort. She's passed a year now and for the many times that I've seem to neglect her, I decided to sit down and play with her idea.
Basically, espionage is the practice of using spies with the aim of obtaining information about the plans and activities of governments and/or competing companies. From thereon, any group could provide counter-measures against those proposed or upcoming businesses. To carry out the delivery of information, various techniques were used to encipher and decipher the information to avoid detection of spying functions.
Among my mother's story comes the basic encryption technique she knew. I forgot where and when she learned of it but the concept remains clear in my memory.
To boot up with, communication can either be of written or verbal form. My mom's idea focused on the written part. Considering that written communication uses the alphabets to form into words to convey meaning, the characters are manipulated in such a way that it would appear to the clueless reader that what he / she had in hand is nothing more than garbage.
So this is how it goes.
Manual Process:
Cipher Key creation:
- Write the alphabet in regular form.
- Create a key with unique letters on it.
For example: rbolsqp
- Write the key as such it aligns with the letters you've written on the first line.
- Following the key, write the alphabet in such manner that you would displace the characters written on the key.
To illustrate:
original alphabet : abcdefghijklmnopqrstuvwxyz
alphabet with key : rbolsqpacdefghijkmntuvwxyz
Enciphering Messages:
- Write a note.
For example,
"go placidly amid the noise and haste,
and remember what peace there may be in silence.
as far as possible without surrender
be on good terms with all persons.
speak your truth quietly and clearly;
and listen to others,
even the dull and the ignorant;
they too have their story."- Re-write the note in such a way that each character is replaced by the corresponding character from the key in line with the original alphabet.
Say, "a" will be replaced by "r",
"b" by "b",
"c" by "o",
"d" by "l",
and so on...Resulting ciphered message:
"pi jfroclfy rgcl tas hicns rhl arnts,
rhl msgsgbsm wart jsros tasms gry bs ch ncfshos.
rn qrm rn jinncbfs wctaiut nummshlsm
bs ih piil tsmgn wcta rff jsmnihn.
njsre yium tmuta kucstfy rhl ofsrmfy;
rhl fcntsh ti itasmn,
svsh tas luff rhl tas cphimrht;
tasy tii arvs tascm ntimy."Deciphering messages:
- Assuming you have the key on hand, reverse the process stated in statement 2 from Enciphering Messages.
As such, "r" will be replaced by "a",
"b" by "b",
"o" by "c",
"l" by "d",
and so forth.Automating the Process Using Visual Basic 6:
- Create a form.
- Add two textboxex and name it txtkey and txtMessageWindow.
- Add four (4) command buttons and name them as cmdDecryptMessage, cmdEncryptUp, cmdMakeKeys and cmdTestKey.
- In the code window, paste the code below:
Dim Keyers(1 To 2, 1 To 26) As String * 1
Dim OriginalKey As String * 26
Dim CryptedKey As String * 26Private Sub cmdDecryptMessage_Click()
Dim tmpStr As String
tmpStr = ""
For x = 1 To Len(txtMessageWindow.Text)
tmpStr = tmpStr + DeCrypt(Mid(txtMessageWindow.Text, x, 1))
Next
txtMessageWindow.Text = tmpStr
End SubPrivate Sub cmdEncryptUp_Click()
Dim tmpStr As String
tmpStr = ""
For x = 1 To Len(txtMessageWindow.Text)
tmpStr = tmpStr + EnCrypt(Mid(txtMessageWindow.Text, x, 1))
Next
txtMessageWindow.Text = tmpStr
End SubPrivate Function EnCrypt(CharItem As String) As String
EnCrypt = CharItem
For x = 1 To 91
If CharItem = Keyers(1, x) Then
EnCrypt = Keyers(2, x)
Exit For
End If
Next
End FunctionPrivate Function DeCrypt(CharItem As String) As String
DeCrypt = CharItem
For x = 1 To 91
If CharItem = Keyers(2, x) Then
DeCrypt = Keyers(1, x)
Exit For
End If
Next
End FunctionPrivate Sub cmdMakeKeys_Click()
CryptedKey = OriginalKey
For x = 1 To Len(txtKey.Text)
CryptedKey = Replace(CryptedKey, Mid(txtKey.Text, x, 1), "")
Next
CryptedKey = txtKey.Text + CryptedKey
For x = 1 To Len(CryptedKey)
Keyers(2, x) = Mid(CryptedKey, x, 1)
Next
End SubPrivate Sub cmdTestKey_Click()
txtMessageWindow.Text = ""
For x = 1 To 26
txtMessageWindow.Text = txtMessageWindow.Text + Keyers(1, x)
Next
txtMessageWindow.Text = txtMessageWindow.Text + vbCrLf
For x = 1 To 26
txtMessageWindow.Text = txtMessageWindow.Text + Keyers(2, x)
Next
End SubPrivate Sub Form_Load()
OriginalKey = "abcdefghijklmnopqrstuvwxyz"
For x = 1 To 26
Keyers(1, x) = Mid(OriginalKey, x, 1)
Next
End Sub
That's just it. How simple it was, and I've let it go a long time before I had it done. Call me indolent then.
Oh my, I miss my mom. And I can't cipher how much I do.
No comments:
Post a Comment