|
-
Sep 10th, 2006, 01:12 AM
#1
Thread Starter
Member
[RESOLVED] [2005] Decryption Algorithm Please Help!
My teacher has given me code for an encryption code and has challenged us to find a working decryption function. I am having a very hard time with this. Can anyone help me out? Here is the Encryption algorithm:
VB Code:
Public Function Encrypt(ByVal strData As String, ByVal strKey As String) As String
Dim k1 As Integer
Dim strCompleteEncrypted As String
Dim s3 As String
Dim intI As Integer
Dim blnFlag As Boolean
Dim intJ As Integer
k1 = 0
strCompleteEncrypted = ""
s3 = ""
intI = strData.Length
blnFlag = False
intJ = intI
For intJ = intI To 1 Step -1
If k1 = strKey.Length Then k1 = 0
Dim intSingleASCValue As Integer
intSingleASCValue = Asc(strKey.Substring(k1, 1))
Dim i1 As Integer
i1 = (intSingleASCValue Mod 13) + 1
If k1 < strKey.Length - 1 Then
Dim k As Integer
k = Asc(strKey.Substring(k1 + 1, 1)) + k1 + 1
If k > 122 Then k = 65 + (122 - k)
Dim intArrayASCValue(0 To strKey.Length - 1) As Integer
Dim intCounter As Integer
For intCounter = 0 To strKey.Length - 1
intArrayASCValue(intCounter) = Asc(strKey.Substring(intCounter, 1))
Next
intArrayASCValue(k1 + 1) = k
Dim intKeyTemp As Integer
intKeyTemp = strKey.Length - 1
strKey = ""
For intCounter = 0 To intKeyTemp
strKey = strKey & Chr(intArrayASCValue(intCounter))
Next
End If
Dim str4 As String
str4 = strData.Substring(intJ - 1, 1)
intSingleASCValue = Asc(str4)
Dim intEncryptedASC2 As Integer
intEncryptedASC2 = intSingleASCValue \ 11
intEncryptedASC2 = 122 - intEncryptedASC2 - i1
Dim intEncryptedASC1 As Integer
intEncryptedASC1 = intSingleASCValue Mod 11
intEncryptedASC1 = 65 + intEncryptedASC1 + i1
Dim strEncrypted1 As String
Dim strEncrypted2 As String
strEncrypted1 = Chr(intEncryptedASC1)
strEncrypted2 = UCase(Chr(intEncryptedASC2))
strCompleteEncrypted = strCompleteEncrypted + strEncrypted1 + strEncrypted2
k1 = k1 + 1
Next
Return strCompleteEncrypted
End Function
Here is a demonstration:
VB Code:
Encrypt("Some Test Encryption Text", "issa_fram")
It returns: INXCDPRITOELFLHPHOENBNHMNDNCMKUNOHQEEOJQPSFNOMCOJP
I realized that the encrypted text length is twice the length of the original data.
When decrypting, the key ("issa_fram") will be provided. Can anyone help me out? I would really appreciate it
-
Sep 10th, 2006, 01:41 AM
#2
Fanatic Member
Re: [2005] Decryption Algorithm Please Help!
Dude, that code sucks. Did your teacher write it badly on purpose? I'm not gonna do that for you, or even figure out how the algorithm works because the code is too messy for my time. I would suggest getting out a piece of paper, creating columns for each variable, and following the algorithm exactly as a computer would. As variable values change, cross of the old value and write the new value below it. Hopefully running through it like a computer would will help you to see what it's doing.
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Sep 10th, 2006, 07:26 AM
#3
Re: [2005] Decryption Algorithm Please Help!
I've been working with cryptography almost 2 years now, and just like DNA7433 said... This doesn't like any algorithm I've ever heard of
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Sep 10th, 2006, 08:58 AM
#4
Fanatic Member
Re: [2005] Decryption Algorithm Please Help!
Well I couldn't sleep tonight and ComputerJy got me looking at it again. It appears that strKey is modified as encoding progresses. Each time a character is encoded the current position in strKey is modified somehow by using the next character in strKey, unless you're currently looking at the last character. Then for each character in your data, two characters are created in the encoding. One shows the value of the current data character integer divide by part of the key, while the other shows modulo. I believe that's the "key" to reproducing the original message. Without both the div and mod values the data from the original message would be lost by either operation. Then there's a lot of mathematical manipulation to make sure all values stay within a particular range, specifically the final result is all uppercase ascii characters.
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Sep 10th, 2006, 09:16 AM
#5
Re: [2005] Decryption Algorithm Please Help!
The key to creating a decryption algorithm is figuring out what the encryption algorithm does. Sounds obvious but unless you can describe in words what the encryption does, as DNA has tried to do, then you can't describe in words what you need to do to create a decryption algorithm so you have nothing to base any code on. You have to understand the problem before you can solve it. The key to that, or any, algorithm is understanding what each individual line does. You should put some line breaks in that code for a start, to make it more readable, and then comment every line. Look at each individual line in isolation and ask yourself what it is doing. Once you know what each line is doing, then you can determine what each block is doing. Once you know what each block is doing then you can determine what the whole is doing. This is how problem solving works: you break the problem up into sub-problems, then each of those into sub-problems and so on until you have lots of tiny problems that are easy to solve in isolation. Once you've done that you put all the individual solutions together and you've solved the original problem. Divide and conquer! I don't believe that there aren't at least some sub-problems in there that you can solve on your own. You should break it up and do all the bits that you can, then post back when you're really stuck. Seriously, if you've just looked at that big block of ugly code and decided you can't do it then you really haven't tried. That would give anybody a headache. You've got to break it down into manageable chunks.
-
Sep 10th, 2006, 11:00 AM
#6
Thread Starter
Member
Re: [2005] Decryption Algorithm Please Help!
The reason I posted it online in the first place was becasue I was having trouble with it. I just thought there would be some experts on the forum. Is there anyone out there who can help me out?
-
Sep 10th, 2006, 11:06 AM
#7
Fanatic Member
Re: [2005] Decryption Algorithm Please Help!
IssaFram, we are the experts, and what we're saying is that we're not going to do the work for you. You said it's a challenge from your teacher. Well it certainly is, but it's not a requirement for your grade. So if you can't figure it out then you won't win the challenge. We can dialog with you about the algorithm, but it sounds like you want someone to write the decryption algorithm for you, is that what you want? No one is going to spend the time figuring out that algorithm so you can win a challenge. What we will do is help you figure it out so you can be a better programmer. So far you haven't told us what you know about the algorithm. Did you understand my overall analysis?
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Sep 10th, 2006, 09:33 PM
#8
Thread Starter
Member
Re: [2005] Decryption Algorithm Please Help!
I think I did understand ur analysis - i was looking through each line of code and trying to duplicate in on paper - like u guys said - and then i got stuck at the mod part. That is when i posted online... I am not ordering you around to just post the code online or anything - obviously u can do what you want - but this is time sensitive and i just wanted some guidance as i can not find a solution with my knowledge. I hope somebody can help, but I thank anyone who has even looked at this.
-
Sep 10th, 2006, 10:04 PM
#9
Re: [2005] Decryption Algorithm Please Help!
If you got stuck on the Mod part you should have said that you got stuck on the Mod part. Then we could have helped you with that part and you could have continued. If you just say "here's my assignment, what do I do?" then you're unlikely to get too many positive responses. If you say "here's my assignment, I've done this this and this but this is giving me trouble" then people will be more inclined to help, as they can see that you've made efforts and you just want help to get past a specific hurdle.
Do you know what the Mod operator does? If not you should look it up in the documentation. Normally you'd use Mod in this type of context to map a number of different objects to the same object. For instance, if you wanted to map the 26 letters of the alphabet to the ten decimal digits you might use Mod.
VB Code:
Dim mappedChar As Char = (Convert.ToInt32(originalChar) Mod 10).ToString().Chars(0)
This takes the Unicode value for the letter and calculates its modulo 10, i.e. the remainder when the value is divided by 10. That can only be a value from 0 to 9, so you map all 26 letters, and any other Unicode character, to a decimal digit. The rest of the code just gets the character representation of that digit.
-
Sep 10th, 2006, 10:15 PM
#10
Thread Starter
Member
Re: [2005] Decryption Algorithm Please Help!
Sorry if I asked the wrong way. But back to the mod thing. I know mod takes the remainder of the division operator - correct? To me it looks like some information is lost in the encryption process. Can you explain a bit more what u mean by the letter assignment? Do you mean that the result of the mod operator will always refer to a single character so u just have to subtract the ASCII value by a certain amount? Would that explain why they did mod 13. 13 is half the letters in the alphabet if i am correct? Please just tell me if i'm going in the right direction. Thx for everything so far.
-
Sep 11th, 2006, 09:52 AM
#11
Thread Starter
Member
Re: [2005] Decryption Algorithm Please Help!
-
Sep 11th, 2006, 07:22 PM
#12
Fanatic Member
Re: [2005] Decryption Algorithm Please Help!
The mapping looks like this in graphical format:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 1 2 3 4 5 6...
A B C D E F G H I J K L M N O P Q R S ...
Suppose each character is given a numerical value (A=1, B=2, C=3, ...) like ASCII. When you take a character and mod it by 13 and then add 1 you will get the mapping above.
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Sep 11th, 2006, 07:30 PM
#13
Fanatic Member
Re: [2005] Decryption Algorithm Please Help!
The decryption algorithm will be basically the same I think as the encryption algorithm. To decrypt you will loop over the encryped string grabbing two characters at a time. You will need to calculate the value of i1 in exactly the same way as is done in the encryption algorithm. Then instead of running these statements for encryption:
VB Code:
Dim str4 As String
str4 = strData.Substring(intJ - 1, 1)
intSingleASCValue = Asc(str4)
Dim intEncryptedASC2 As Integer
intEncryptedASC2 = intSingleASCValue \ 11
intEncryptedASC2 = 122 - intEncryptedASC2 - i1
Dim intEncryptedASC1 As Integer
intEncryptedASC1 = intSingleASCValue Mod 11
intEncryptedASC1 = 65 + intEncryptedASC1 + i1
Dim strEncrypted1 As String
Dim strEncrypted2 As String
strEncrypted1 = Chr(intEncryptedASC1)
strEncrypted2 = UCase(Chr(intEncryptedASC2))
strCompleteEncrypted = strCompleteEncrypted + strEncrypted1 + strEncrypted2
k1 = k1 + 1
you'll reverse those calculations to determine the ASCII value of the decrypted character. For the first of the two characters you reverse this formula:
VB Code:
intEncryptedASC2 = 122 - intEncryptedASC2 - i1
and for the second, reverse this formula:
VB Code:
intEncryptedASC1 = 65 + intEncryptedASC1 + i1
Then those two values provide your original value divided by i1 and mod i1. Do you know how to reconstruct a number, say 51, if I give you two values: 10 (51 \ 5) and 1 (51 mod 5)?
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Sep 11th, 2006, 08:45 PM
#14
Thread Starter
Member
Re: [2005] Decryption Algorithm Please Help!
When you say reverse the formula, do you mean I should think of it like algebra and say
VB Code:
intEncryptedASC1 = intEncryptedASC1 - i1 - 65
or am i wrong. Another question. You say I should grab 2 letters at a time. I had that same idea but I'm not sure if i should start at the end (right side) or beginning(left side)?
Then those two values provide your original value divided by i1 and mod i1. Do you know how to reconstruct a number, say 51, if I give you two values: 10 (51 \ 5) and 1 (51 mod 5)?
I know how to mod and i know how to do that division (i think integer division truncating decimal?) but I am not sure what you want me to do. Thank you and please keep helping. It is greatly appreciated.
-
Sep 11th, 2006, 09:00 PM
#15
Fanatic Member
Re: [2005] Decryption Algorithm Please Help!
Yes it is just like algebra.
As to whether to start at the left or right side - think about this. The encryption algorithm starts with a key and modifies it as it is encrypting. Since the original key is provided for decryption (not the modified key) you can only decrypt the characters that were encrypted using that key. Hence, you have to start at the left.
Correct, it just truncates the decimal portion - no rounding.
Look at the case I gave you and see if you can find a formula for calculating the original value. Integer quotient = 10, remainder = 1, and divisor = 5, what was the original value? There's a very simple formula for finding it.
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Sep 11th, 2006, 09:09 PM
#16
Thread Starter
Member
Re: [2005] Decryption Algorithm Please Help!
after thinking about it i think we would need x from these expressions:
x \ 5 = 10
x mod 5 = 1
right?
just using my brain (could probly code it somewhow) i figured out it was 51.
what from there?
thanks again
btw - u got AIM or Skype or something? easier to talk to
-
Sep 11th, 2006, 09:16 PM
#17
Fanatic Member
Re: [2005] Decryption Algorithm Please Help!
I use AIM, check your private messages.
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Sep 11th, 2006, 09:18 PM
#18
Thread Starter
Member
Re: [2005] Decryption Algorithm Please Help!
Since i'm getting the feeling that I might actually be able to do this, let me post what i have...
VB Code:
Public Function Decrypt(ByVal strEncryptedData As String, ByVal strKey As String) As String
Dim strCompleteOriginal As String
strCompleteOriginal = ""
Dim i As Integer
For i = 0 To strEncryptedData.Length - 1 Step 2
Dim strFirstLetter As String
Dim strSecondLetter As String
strFirstLetter = strEncryptedData.Substring(i, 1)
strSecondLetter = strEncryptedData.Substring(i + 1, 1)
Debug.Print("First Letter: " & strFirstLetter & vbCrLf & "Second Letter: " & strSecondLetter)
Next
'Return strCompleteOriginal
End Function
Yes I know its not much. I think once i get to that part where s4 is being used I will be fine. But the code before that looks tough. I'm not sure how to use the key or do i just encrypt again? Thanks again man.
-
Sep 11th, 2006, 09:42 PM
#19
New Member
Re: [2005] Decryption Algorithm Please Help!
-
Sep 11th, 2006, 11:54 PM
#20
Thread Starter
Member
Re: [2005] Decryption Algorithm Please Help!
I already got the answer thanks to someone's help. THX!!!!!!!!!!!
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
|