Results 1 to 6 of 6

Thread: Where do I start?

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Posts
    1

    Post

    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

  2. #2
    Hyperactive Member
    Join Date
    Sep 1999
    Posts
    305

    Post

    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

  3. #3
    Addicted Member
    Join Date
    Feb 2000
    Location
    London, UK
    Posts
    145

    Post

    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!

  4. #4
    Hyperactive Member
    Join Date
    Sep 1999
    Posts
    305

    Post

    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.

  5. #5
    Guest

    Post

    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]

  6. #6
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Post

    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
  •  



Click Here to Expand Forum to Full Width