Results 1 to 20 of 20

Thread: [RESOLVED] [2005] Decryption Algorithm Please Help!

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2004
    Posts
    52

    Resolved [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:
    1. Public Function Encrypt(ByVal strData As String, ByVal strKey As String) As String
    2.         Dim k1 As Integer
    3.         Dim strCompleteEncrypted As String
    4.         Dim s3 As String
    5.         Dim intI As Integer
    6.         Dim blnFlag As Boolean
    7.         Dim intJ As Integer
    8.         k1 = 0
    9.         strCompleteEncrypted = ""
    10.         s3 = ""
    11.         intI = strData.Length
    12.         blnFlag = False
    13.         intJ = intI
    14.         For intJ = intI To 1 Step -1
    15.             If k1 = strKey.Length Then k1 = 0
    16.             Dim intSingleASCValue As Integer
    17.             intSingleASCValue = Asc(strKey.Substring(k1, 1))
    18.             Dim i1 As Integer
    19.             i1 = (intSingleASCValue Mod 13) + 1
    20.             If k1 < strKey.Length - 1 Then
    21.                 Dim k As Integer
    22.                 k = Asc(strKey.Substring(k1 + 1, 1)) + k1 + 1
    23.                 If k > 122 Then k = 65 + (122 - k)
    24.                 Dim intArrayASCValue(0 To strKey.Length - 1) As Integer
    25.                 Dim intCounter As Integer
    26.                 For intCounter = 0 To strKey.Length - 1
    27.                     intArrayASCValue(intCounter) = Asc(strKey.Substring(intCounter, 1))
    28.                 Next
    29.                 intArrayASCValue(k1 + 1) = k
    30.                 Dim intKeyTemp As Integer
    31.                 intKeyTemp = strKey.Length - 1
    32.                 strKey = ""
    33.                 For intCounter = 0 To intKeyTemp
    34.                     strKey = strKey & Chr(intArrayASCValue(intCounter))
    35.                 Next
    36.             End If
    37.             Dim str4 As String
    38.             str4 = strData.Substring(intJ - 1, 1)
    39.             intSingleASCValue = Asc(str4)
    40.             Dim intEncryptedASC2 As Integer
    41.             intEncryptedASC2 = intSingleASCValue \ 11
    42.             intEncryptedASC2 = 122 - intEncryptedASC2 - i1
    43.             Dim intEncryptedASC1 As Integer
    44.             intEncryptedASC1 = intSingleASCValue Mod 11
    45.             intEncryptedASC1 = 65 + intEncryptedASC1 + i1
    46.             Dim strEncrypted1 As String
    47.             Dim strEncrypted2 As String
    48.             strEncrypted1 = Chr(intEncryptedASC1)
    49.             strEncrypted2 = UCase(Chr(intEncryptedASC2))
    50.             strCompleteEncrypted = strCompleteEncrypted + strEncrypted1 + strEncrypted2
    51.             k1 = k1 + 1
    52.         Next
    53.         Return strCompleteEncrypted
    54.     End Function

    Here is a demonstration:
    VB Code:
    1. 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
    -Issa Fram

  2. #2
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    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.

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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

  4. #4
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    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.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Member
    Join Date
    Oct 2004
    Posts
    52

    Exclamation 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?
    -Issa Fram

  7. #7
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    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.

  8. #8

    Thread Starter
    Member
    Join Date
    Oct 2004
    Posts
    52

    Exclamation 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.
    -Issa Fram

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    Member
    Join Date
    Oct 2004
    Posts
    52

    Exclamation 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.
    -Issa Fram

  11. #11

    Thread Starter
    Member
    Join Date
    Oct 2004
    Posts
    52

    Exclamation Re: [2005] Decryption Algorithm Please Help!

    ^
    |
    |
    | bump
    -Issa Fram

  12. #12
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    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.

  13. #13
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    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:
    1. Dim str4 As String
    2.             str4 = strData.Substring(intJ - 1, 1)
    3.             intSingleASCValue = Asc(str4)
    4.             Dim intEncryptedASC2 As Integer
    5.             intEncryptedASC2 = intSingleASCValue \ 11
    6.             intEncryptedASC2 = 122 - intEncryptedASC2 - i1
    7.             Dim intEncryptedASC1 As Integer
    8.             intEncryptedASC1 = intSingleASCValue Mod 11
    9.             intEncryptedASC1 = 65 + intEncryptedASC1 + i1
    10.             Dim strEncrypted1 As String
    11.             Dim strEncrypted2 As String
    12.             strEncrypted1 = Chr(intEncryptedASC1)
    13.             strEncrypted2 = UCase(Chr(intEncryptedASC2))
    14.             strCompleteEncrypted = strCompleteEncrypted + strEncrypted1 + strEncrypted2
    15.             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:
    1. intEncryptedASC2 = 122 - intEncryptedASC2 - i1
    and for the second, reverse this formula:
    VB Code:
    1. 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.

  14. #14

    Thread Starter
    Member
    Join Date
    Oct 2004
    Posts
    52

    Exclamation 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:
    1. 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.
    -Issa Fram

  15. #15
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    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.

  16. #16

    Thread Starter
    Member
    Join Date
    Oct 2004
    Posts
    52

    Exclamation 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
    -Issa Fram

  17. #17
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    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.

  18. #18

    Thread Starter
    Member
    Join Date
    Oct 2004
    Posts
    52

    Exclamation 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:
    1. Public Function Decrypt(ByVal strEncryptedData As String, ByVal strKey As String) As String
    2.         Dim strCompleteOriginal As String
    3.         strCompleteOriginal = ""
    4.         Dim i As Integer
    5.         For i = 0 To strEncryptedData.Length - 1 Step 2
    6.             Dim strFirstLetter As String
    7.             Dim strSecondLetter As String
    8.             strFirstLetter = strEncryptedData.Substring(i, 1)
    9.             strSecondLetter = strEncryptedData.Substring(i + 1, 1)
    10.             Debug.Print("First Letter: " & strFirstLetter & vbCrLf & "Second Letter: " & strSecondLetter)
    11.         Next
    12.         'Return strCompleteOriginal
    13.     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.
    -Issa Fram

  19. #19
    New Member
    Join Date
    Sep 2006
    Posts
    6

    Re: [2005] Decryption Algorithm Please Help!


  20. #20

    Thread Starter
    Member
    Join Date
    Oct 2004
    Posts
    52

    Smile Re: [2005] Decryption Algorithm Please Help!

    I already got the answer thanks to someone's help. THX!!!!!!!!!!!
    -Issa Fram

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