|
-
Feb 5th, 2000, 03:48 AM
#1
Thread Starter
New Member
i need to write a program for class homework to solve this problem: A company transmits data over the telephone, but they want it encrypted. All their transmissions a four-digit integers. I need to read the integer and encrypt it as follows: Replace each digit by (the sum of that digit plus 7) modulus 10. Then, swap the first digit with the third, and the second with the fourth. Then print the encrypted integer. Does anyone have any suggestions/solutions?
Thanks,
Reid
-
Feb 5th, 2000, 05:31 AM
#2
Hyperactive Member
I believe this is what you want. I have two textboxes. The first is the input, the second is the output.
Private Sub Text1_Change()
If Len(Text1.Text) = 4 Then
FRST = Right(Left(Text1.Text, 1) + 7, 1)
SCND = Right(Mid(Text1.Text, 2, 1) + 7, 1)
THRD = Right(Mid(Text1.Text, 3, 1) + 7, 1)
FRTH = Right(Right(Text1.Text, 1) + 7, 1)
SCNDSTEP = FRST & SCND & THRD & FRTH
LFT = Left(SCNDSTEP, 2)
RGT = Right(SCNDSTEP, 2)
Text2.Text = RGT & LFT
End If
End Sub
Hope it works for you.
P.S. I had fun writing this. 
bob
-
Feb 5th, 2000, 05:45 AM
#3
Addicted Member
It would be a good idea to clear the first textbox as well.
Input Text1.Text = ""
Before the 'End If'
Else, the function will only work once, the first time (when Len(Text1.Text) = 4).
Also you need to get the modulus part in somwhere, preferably after adding 7
Good luck!
------------------
Wilhelm Tunemyr,
Sweden
[email protected]
"Dort, wo man Bücher verbrennt, verbrennt man am Ende auch Menchen"
Heinrich Heine (1797-1856)
Pravda zvítezi!
-
Feb 5th, 2000, 06:47 AM
#4
Hyperactive Member
okey dokey. Well, what I have will add 7 to each one, but only keep the first digit if it goes over 9, then switch the 1,3 and 2,4, which is the same thing as switching the left and right halves.
-
Feb 6th, 2000, 01:21 AM
#5
tell your class teacher, that I think this is a lousy way of encrytping things. Does (s)he know about XOR?
------------------
Wossname,
Email me: [email protected]
-
Feb 6th, 2000, 12:15 PM
#6
Fanatic Member
Pardon the lack of error checking (digit count etc)...
Private Sub Command1_Click()
Dim Num As String
Dim Digits As Integer
Dim CurrentInt As Integer
Dim Values(4) As Integer
Num = Text1.Text 'Processing needs to happen numerically but the input must come as separately as text
For Digits = 1 To 4
CurrentInt = CInt(Mid(Num, Digits, 1))
Values(Digits) = (CurrentInt + 7) Mod 10
Next
Label1.Caption = Values(3) & Values(4) & Values(1) & Values(2)
End Sub
PS, forget the >9 stuff you're using mod 10 so you'll never have this problem (I imagine that you teacher thought of this)
[This message has been edited by Paul282 (edited 02-06-2000).]
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
|