Results 1 to 7 of 7

Thread: If Not Reverse Mod, Then What???

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2002
    Location
    Maine
    Posts
    29

    Question If Not Reverse Mod, Then What???

    thanks to those of you that answered my original question... It's good to know that there is no possible answer... but that still leaves me with an unanswered question... My frist question was how do I "unmod" a number that has been moded in the program below.... I now know that it is impossible to write a program that will unmod any random number... perhaps then there is a way to decrypt the originally encrypted message without "un"moding the digits???

    Here is the question word for word, let me know what you think!!Maybe I am interpreting it wrong...

    "A company wants to trasnmit data over the telephone, but they are concerned that their phones may be tapped. All their data is transmitted as four-digit integers. They have asked you to write a program that encrypts their data so that it may be transmitted more securely. Your program should read a four digit integer entered by the user and encrypt it as follows: Replace each digit by (the sum of that digit plus 7) modulo 10. THen swap the first digit with the third, and swap the second digit with the fourth. Print the encrypted integer. Write a separate program that inputs an encrypted four digit integer and decrypts it to form the original number. "

    Here is the code again for the first part of the problem:

    Module Module1

    Sub Main()

    Dim digit As Integer
    Dim placeOne, placeTwo, placeThree, placeFour As Integer
    Dim oneSwap, twoSwap, threeSwap, fourSwap As Integer

    Console.Write("Please enter the four-digit integer: ")
    digit = Console.ReadLine()

    placeFour = digit \ 1 Mod 10
    placeThree = digit \ 10 Mod 10
    placeTwo = digit \ 100 Mod 10
    placeOne = digit \ 1000 Mod 10

    placeOne = (placeOne + placeOne + 7) Mod 10
    placeTwo = (placeTwo + placeTwo + 7) Mod 10
    placeThree = (placeThree + placeThree + 7) Mod 10
    placeFour = (placeFour + placeFour + 7) Mod 10

    oneSwap = placeThree
    twoSwap = placeFour
    threeSwap = placeOne
    fourSwap = placeTwo

    Console.WriteLine(oneSwap & twoSwap & threeSwap & fourSwap)

    End Sub

    End Module


    Thank you in advance to anyone who helps me with this thing!!!! I'm new at this, and I'm not much of a logical thinker really...

  2. #2
    Fanatic Member
    Join Date
    Jun 2001
    Posts
    521
    You should not have made a new thread for this. There IS no solution. All you can do is guess that the resulting number is one of 16 original numbers.

  3. #3
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    There's NO way to decrypt this. For example, what if placeOne = 6... what would be the original value?? You have two possible original values that would return 9:. For example:

    placeOne = (placeOne + placeOne + 7) Mod 10
    (1 + 1 + 7) Mod 10 = 9
    (6 + 6 + 7) Mod 10 = 9

    See?? Which was the original one? 6 or 1??

    Other examples.... all of them has two posible original values:

    (2 + 2 + 7) Mod 10 = 1
    (7 + 7 + 7) Mod 10 = 1

    (3 + 3 + 7) Mod 10 = 3
    (8 + 8 + 7) Mod 10 = 3

    (4 + 4 + 7) Mod 10 = 5
    (9 + 9 + 7) Mod 10 = 5

    (5 + 5 + 7) Mod 10 = 7
    (0 + 0 + 7) Mod 10 = 7
    Last edited by Mc Brain; Sep 28th, 2002 at 10:49 AM.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    In this exercise, we look at one method of encryption. A message is first broken up into pairs of consecutive characters Each pair is converted to a four digit number by using the ASCII values of the characters; for example, BY is converted to 6689 because the ASCII value for B is 66 and the ASCII value for Y is 89.

    Then we add 7 mod 10 to each digit. This is done by adding 7 to the digit and taking the remainder on dividing by 10: e.g., the sum of 6 and 7 is 3. . In our example, the result of adding 7 (mod 10) to each digit of 6689 is 3356.

    Finally, we swap the first and fourth digit and the second and third digit. In our example, this will produce 6533, the encrypted form of BY

    (a) Show that GO is encrypted as 6484

    (b) Encrypt your initials.

    (c) Decrypt 2314 2335

    (d) Do you think this method provides a secure encryption scheme? Explain.


    http://community.middlebury.edu/~mol...gnment_17.html

  5. #5
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    0+7=7
    1+7=8
    2+7=9
    3+7=0
    4+7=1
    5+7=2
    6+7=3
    7+7=4
    8+7=5
    9+7=6

    Ok, then.... that's decryptable!!!
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  6. #6
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Guess that military training paid off... you should of never left the CIA..

  7. #7
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Debug.Print Encrypt("BY")
    5.    
    6.     Debug.Print Decrypt(6533)
    7. End Sub
    8.  
    9. Private Function Encrypt(ByVal Word As String) As Integer
    10.     Dim i As Integer
    11.    
    12.     Word = Asc(Word) & Asc(Mid$(Word, 2))
    13.  
    14.     For i = 1 To 4
    15.         Mid$(Word, i, 1) = (Mid$(Word, i, 1) + 7) Mod 10
    16.     Next i
    17.    
    18.     Word = SwapValues(Word, 1, 4)
    19.     Word = SwapValues(Word, 2, 3)
    20.    
    21.     Encrypt = Word
    22.    
    23. End Function
    24.  
    25. Private Function SwapValues(ByVal Word As String, First As Integer, Second As Integer) As String
    26.     Dim tempstring As String
    27.        
    28.     SwapValues = Mid$(Word, First, 1)
    29.     Mid$(Word, First, 1) = Mid$(Word, Second, 1)
    30.     Mid$(Word, Second, 1) = SwapValues
    31.    
    32.     SwapValues = Word
    33. End Function
    34.  
    35. Private Function Decrypt(ByVal Word As String) As String
    36.     Dim i As Integer
    37.     Dim TempValue As Integer
    38.    
    39.     Word = SwapValues(Word, 1, 4)
    40.     Word = SwapValues(Word, 2, 3)
    41.  
    42.     For i = 1 To 4
    43.         TempValue = (Mid$(Word, i, 1) - 7)
    44.        
    45.         If TempValue < 0 Then TempValue = TempValue + 10
    46.        
    47.         Mid$(Word, i, 1) = TempValue
    48.     Next i
    49.  
    50.     Word = Chr$(Left$(Word, 2)) & Chr$(Mid$(Word, 3))
    51.    
    52.     Decrypt = Word
    53.    
    54. End Function
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

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