|
-
Sep 28th, 2002, 09:54 AM
#1
Thread Starter
Junior Member
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...
-
Sep 28th, 2002, 09:57 AM
#2
Fanatic Member
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.
-
Sep 28th, 2002, 10:45 AM
#3
-
Sep 28th, 2002, 11:00 AM
#4
I wonder how many charact
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
-
Sep 28th, 2002, 11:05 AM
#5
-
Sep 28th, 2002, 11:14 AM
#6
I wonder how many charact
Guess that military training paid off... you should of never left the CIA..
-
Sep 28th, 2002, 11:18 AM
#7
Need-a-life Member
VB Code:
Option Explicit
Private Sub Form_Load()
Debug.Print Encrypt("BY")
Debug.Print Decrypt(6533)
End Sub
Private Function Encrypt(ByVal Word As String) As Integer
Dim i As Integer
Word = Asc(Word) & Asc(Mid$(Word, 2))
For i = 1 To 4
Mid$(Word, i, 1) = (Mid$(Word, i, 1) + 7) Mod 10
Next i
Word = SwapValues(Word, 1, 4)
Word = SwapValues(Word, 2, 3)
Encrypt = Word
End Function
Private Function SwapValues(ByVal Word As String, First As Integer, Second As Integer) As String
Dim tempstring As String
SwapValues = Mid$(Word, First, 1)
Mid$(Word, First, 1) = Mid$(Word, Second, 1)
Mid$(Word, Second, 1) = SwapValues
SwapValues = Word
End Function
Private Function Decrypt(ByVal Word As String) As String
Dim i As Integer
Dim TempValue As Integer
Word = SwapValues(Word, 1, 4)
Word = SwapValues(Word, 2, 3)
For i = 1 To 4
TempValue = (Mid$(Word, i, 1) - 7)
If TempValue < 0 Then TempValue = TempValue + 10
Mid$(Word, i, 1) = TempValue
Next i
Word = Chr$(Left$(Word, 2)) & Chr$(Mid$(Word, 3))
Decrypt = Word
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|