|
-
Oct 4th, 2000, 06:09 AM
#1
Thread Starter
New Member
Can anyone help me?
a) I must write a program that encrypts a meesage using rot13
b) Then i must decrypt the skrambled message using 13 as the key.
My code looks like this now:
Option Explicit
Dim mAlfabet As String
Private Sub cmdDeKrypter_Click()
Dim Melding As String
Dim Tegn As String
Dim teller As Single
Dim foran As String
Dim bak As String
Dim antallTegn As Integer
Dim temp As Integer
Dim res As String
Melding = txtMelding.Text
For teller = 1 To Len(Melding)
bak = Right(Melding, Len(Melding) + teller)
Melding = foran & Tegn & bak
txtOutputKrypter.Text = txtOutputKrypter.Text
txtOutputKrypter.Text = ""
Next teller
MsgBox Melding
End Sub
Private Sub cmdKrypter_Click()
Dim Melding As String
Dim Tegn As String
Dim teller As Single
Dim foran As String
Dim bak As String
Dim antallTegn As Integer
Dim temp As Integer
Dim res As String
Melding = txtMelding.Text
For teller = 1 To Len(Melding)
Tegn = Mid$(Melding, teller, 1)
temp = InStr(1, mAlfabet, Tegn, vbBinaryCompare)
Tegn = Mid$(mAlfabet, temp + 13, 1)
foran = Left(Melding, teller - 1)
bak = Right(Melding, Len(Melding) - teller)
Melding = foran & Tegn & bak
txtOutputKrypter.Text = txtOutputKrypter.Text
txtOutputKrypter.Text = ""
Next teller
MsgBox Melding
End Sub
Private Sub Form_Load()
mAlfabet = "abcdefghijklmnopqrstuvwxyzabcdefghijklmn"
End Sub
Private Sub mnuAvslutt_Click()
End
End Sub
Thank you!
-
Oct 4th, 2000, 06:55 AM
#2
Fanatic Member
Try the following
Should explain the process in the coments
Code:
'/////////////////////////////////////////////////////////////////////////
'// //
'// Purpose: To encrypt/decrypt passwords or other short text. //
'// ___________________________________________________________________ //
'// //
'// Inputs: strText: as the text to encrypt/decrypt. //
'// strCipherText: scrambler code for encryption/decryption. //
'// intAction: switch for encrypt/decrypt //
'// K_DECRYPT = 0 //
'// K_ENCRYPT = 1 //
'// ___________________________________________________________________ //
'// //
'// Returns: Encryped [strPlainText] or decypted [strCipherText]. //
'// //
'// ___________________________________________________________________ //
'// Author: Jerry Grant Touch-base 2000 : 22/02/2000 //
'/////////////////////////////////////////////////////////////////////////
Public Function F_SimpleCrypt( _
ByVal strText As String, _
ByVal strCipherText As String, _
ByVal intAction As Integer _
) As String
Dim lngLoop As Long
Dim intPrev As Integer
Dim intChar As Integer
Dim intKeyIndex As Integer
Dim intKeyLen As Integer
Dim strTextValue As String
Dim strResultCode As String
Dim intNewChar As Integer
Dim intEncrypting As Integer
ReDim intAKeyChar(255) As Integer
'//'Magic values' used for en/decryption. DO NOT CHANGE THESE. //
Const K_MAGIC1 = 42
Const K_MAGIC2 = 3
'//Determine if we're encrypting or decrypting //
If intAction = K_DECRYPT Then
intEncrypting = False
Else
intEncrypting = True
End If
strTextValue = strText
'//Initialize 'previous character' value, index into //
'//key string and length of key //
intPrev = K_MAGIC1: intKeyIndex = 1
intKeyLen = Len(strCipherText)
'//Convert key string to array //
For lngLoop = 1 To Len(strCipherText)
intAKeyChar(lngLoop) = Asc(Mid(strCipherText, lngLoop, 1))
Next lngLoop
'//Actual en/decryption loop //
For lngLoop = 1 To Len(strTextValue)
intChar = Asc(Mid(strTextValue, lngLoop, 1))
intNewChar = intChar Xor intAKeyChar(intKeyIndex) _
Xor intPrev _
Xor ((lngLoop / K_MAGIC2) Mod 255)
strResultCode = strResultCode & Chr(intNewChar)
If intEncrypting Then
intPrev = intChar
Else
intPrev = intNewChar
End If
intKeyIndex = intKeyIndex + 1
If intKeyIndex > intKeyLen Then intKeyIndex = 1
Next lngLoop
'//Return strResultCode to caller //
F_SimpleCrypt = strResultCode
End Function
[Edited by Jerry Grant on 10-04-2000 at 08:04 AM]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|