87 lines
2.2 KiB
Plaintext
87 lines
2.2 KiB
Plaintext
Function Encipher(bd As String, pt As String) As String
|
|
Dim As String enc(256), row(3), r2d, r3d, d, num, ct
|
|
Dim As Integer i = 1, j, col
|
|
|
|
For j = 0 To 3
|
|
row(j) = Mid(bd, i, Instr(i, bd, Chr(10)) - i)
|
|
i = Instr(i, bd, Chr(10)) + 1
|
|
Next j
|
|
r2d = Mid(row(2), 1, 1)
|
|
r3d = Mid(row(3), 1, 1)
|
|
For col = 1 To 10
|
|
d = Mid(row(0), col+1, 1)
|
|
enc(Asc(Mid(row(1), col+1, 1))) = d
|
|
enc(Asc(Mid(row(2), col+1, 1))) = r2d + d
|
|
enc(Asc(Mid(row(3), col+1, 1))) = r3d + d
|
|
Next col
|
|
num = enc(Asc("/"))
|
|
enc(Asc("/")) = ""
|
|
enc(Asc(" ")) = ""
|
|
ct = ""
|
|
For i = 0 To Len(pt)-1
|
|
j = Asc(Mid(pt, i+1, 1))
|
|
If j <= Asc("9") And j >= Asc("0") Then
|
|
ct += num + Chr(j)
|
|
Else
|
|
If j <= Asc("z") And j >= Asc("a") Then
|
|
j -= Asc("a") - Asc("A")
|
|
End If
|
|
ct += enc(j)
|
|
End If
|
|
Next i
|
|
Return ct
|
|
End Function
|
|
|
|
Function Decipher(bd As String, ct As String) As String
|
|
Dim As String row(3), pt, b
|
|
Dim As Integer i = 1, j, cx(10), r2d, r3d, r, d
|
|
|
|
For j = 0 To 3
|
|
row(j) = Mid(bd, i, Instr(i, bd, Chr(10)) - i)
|
|
i = Instr(i, bd, Chr(10)) + 1
|
|
Next j
|
|
|
|
For i = 1 To 10
|
|
cx(Asc(Mid(row(0), i+1, 1)) - Asc("0")) = i
|
|
Next i
|
|
r2d = Asc(Mid(row(2), 1, 1)) - Asc("0")
|
|
r3d = Asc(Mid(row(3), 1, 1)) - Asc("0")
|
|
pt = ""
|
|
i = 0
|
|
While i < Len(ct)
|
|
d = Asc(Mid(ct, i+1, 1)) - Asc("0")
|
|
If d = r2d Then
|
|
r = 2
|
|
Elseif d = r3d Then
|
|
r = 3
|
|
Else
|
|
pt += Mid(row(1), cx(d)+1, 1)
|
|
i += 1
|
|
Continue While
|
|
End If
|
|
i += 1
|
|
b = Mid(row(r), cx(Asc(Mid(ct, i+1, 1)) - Asc("0"))+1, 1)
|
|
If b = "/" Then
|
|
i += 1
|
|
pt += Mid(ct, i+1, 1)
|
|
Else
|
|
pt += b
|
|
End If
|
|
i += 1
|
|
Wend
|
|
Return pt
|
|
End Function
|
|
|
|
Dim As String key = _
|
|
" 8752390146" + Chr(10) + _
|
|
" ET AON RIS" + Chr(10) + _
|
|
"5BC/FGHJKLM" + Chr(10) + _
|
|
"0PQD.VWXYZU"
|
|
Dim p As String = "you have put on 7.5 pounds since I saw you."
|
|
Print p
|
|
Dim c As String = Encipher(key, p)
|
|
Print c
|
|
Print Decipher(key, c)
|
|
|
|
Sleep
|