Reversing an algorithm

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Thekid
    New Member
    • Feb 2007
    • 145

    Reversing an algorithm

    Hi,
    This code works fine but what I need is to reverse the algorithm somehow. Is there a simple solution to this? I would need to take numbers in the format as the printed out answer and have them reversed so the code would print out the answer in the format as the 'serial numbers' are in:

    Code:
    from hashlib import md5
    evalCrossTotal = lambda strMD5: sum(map(lambda x: int(x, 16), strMD5))
    def encryptString(strString, strPassword):
        # strString is the content of the entire file with serials
        strPasswordMD5 = md5(strPassword).hexdigest()
        intMD5Total = evalCrossTotal(strPasswordMD5)
        arrEncryptedValues = []
        for i in range(len(strString)):
            arrEncryptedValues.append(
                str(ord(strString[i]) + int(strPasswordMD5[i%32], 16) - intMD5Total)
            )
            intMD5Total = evalCrossTotal(
                md5(strString[0:i+1]).hexdigest()[0:16] +
                md5(str(intMD5Total)).hexdigest()[0:16]
            )
        return ' '.join(arrEncryptedValues)
    # serial numbers
    strString = """99Z-KH5-OEM-240-1.1
       QGG-V33-OEM-0B1-1.1
       Z93-Z29-OEM-BNX-1.1
       IQ0-PZI-OEM-PK0-1.1
       UM4-VDL-OEM-B9O-1.1
       L0S-4R2-OEM-UQL-1.1
       JBL-EYQ-OEM-ABB-1.1
       NL1-3V3-OEM-L4C-1.1
       7CQ-1ZR-OEM-U3I-1.1
       XX0-IHL-OEM-5XK-1.1
       KJQ-RXG-OEM-TW8-1.1
       OZR-LW1-OEM-5EM-1.1
       0B8-6K5-OEM-EFN-1.1
       OE2-20L-OEM-SSI-1.1
       0ME-HAE-OEM-9XB-1.1"""
    print encryptString(strString, "strPassword")

    Results(partial answer print out for the sake of space):
    Code:
    -195 -208 -172 -218 -143 -99 -164 -230 -185 -150 -137 -196 -188 -134 -195 -223 -212 -235 -185 -251 -249 -202 -226 -127 -163 -154 -203 -167 -216 -170 -162 -149 -139 -124 -172 -149 -184 -156 -159 -167 -138 -211 -227 -173 -171 -217 -124 -142 -218 -166 -181 -142 -205 -173 -124 -166 -156 -223 -123 -161 -134 -202 -200 -182 -
    Instead, I would need to take numbers in the above format and have them print out in this format:
    Code:
       99Z-KH5-OEM-240-1.1
       QGG-V33-OEM-0B1-1.1
       Z93-Z29-OEM-BNX-1.1
       IQ0-PZI-OEM-PK0-1.1
       UM4-VDL-OEM-B9O-1.1
       L0S-4R2-OEM-UQL-1.1
       JBL-EYQ-OEM-ABB-1.1
       NL1-3V3-OEM-L4C-1.1
       7CQ-1ZR-OEM-U3I-1.1
       XX0-IHL-OEM-5XK-1.1
       KJQ-RXG-OEM-TW8-1.1
       OZR-LW1-OEM-5EM-1.1
       0B8-6K5-OEM-EFN-1.1
       OE2-20L-OEM-SSI-1.1
       0ME-HAE-OEM-9XB-1.1"""
    Any suggestions?
  • Smygis
    New Member
    • Jun 2007
    • 126

    #2
    I love you're excessive use of comments.

    Yeah its super simple. md5 is a one way hash. You cant reverse it.

    Comment

    • Thekid
      New Member
      • Feb 2007
      • 145

      #3
      Originally posted by Smygis
      I love you're excessive use of comments.

      Yeah its super simple. md5 is a one way hash. You cant reverse it.
      I'll be sure and give that as my answer. If you don't understand what I'm asking, please check with me and I will clarify it.

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, TheKid.

        Care to tell us why you want to crack this encryption algorithm?

        Comment

        • RedSon
          Recognized Expert Expert
          • Jan 2007
          • 4980

          #5
          Is this question about how to make the ouput change? Or is it an encryption question?

          Comment

          Working...