Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 7th, 2005, 4:39 PM   #1
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,868
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Grrrr I need Math Programming help.

I'm creating an encryption program for some time off, and I haven't learned this stuff so I'm having a little bit of trouble.

It's supposed to use abc of the quadratic equation to alter the ascii, and then convert back. But I can't figure out how to reverse a quadratic equation.

I know to change an x to a y in a quadratic equation is
y = x**a + x*b + c

and to get the intercepts of x is

x = -b +- ([b**2 - 4ac]**0.5 / 2a)

but how can I convert y back to x?

For example.

Say the character is 's', when converted to ascii that is 115 (alt + 115).

Now the quadratic equation is:
y = x**a + x*b + c
and we'll say a =1, b = 2, c = 3

so now it is 233.

converted back into ascii is Θ .

But now when it's time to decrypt, how do I get 233 back to 115?

I think it's something like:

x = -b +- ([b**2 - 4ac]**0.5 / 2a)

original X = x * 233

Can someone help?
Sane is offline   Reply With Quote
Old Jul 7th, 2005, 5:10 PM   #2
mackenga
Professional Programmer
 
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 317
Rep Power: 4 mackenga is on a distinguished road
y = x**a + x * b + c

I assume you're using the ** operator to denote exponentiation. First up, in your example, if x = 115, y != 233; y == 115 ** 1 + 2 * 115 + 3 == 115 + 230 + 3 == 348. Chars are just one byte, but 348 > 2 ** 8, so you will need more than one byte per character for your ciphertext to do it this way (unless there's some funky trick I'm not thinking of off the top of my head, which is possible since the ciphertext will still only contain 256 distinct values).

As for reversing the encryption; first, you can subtract 3 (the 3 added at the end of the encryption process) to get x ** a + x * b == 345. a and b are 1 and 2 respectively, so that's x ** 1 + x * 2 = 345. Any number n to the first power is just n, so you have 3 * x = 345, => x = 345/3 = 115 = your plaintext character s.

This encryption system has a few problems, the most serious of which is that each character of plaintext will still always map to a particular value in the ciphertext, which means this is trivial to crack using frequency analysis and all the mathematical stuff is beside the point.
mackenga is offline   Reply With Quote
Old Jul 7th, 2005, 7:44 PM   #3
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,868
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
First Paragraph: Ya, I was rushing an example, sorry I missed the initial 115. Once it gets passed 256 it loops to 0, and vice-versa.

Second Paragraph: Okay, thanks. But that still doesn't give me a formula because it won't work if the encryptor chooses > 1 for a.

Third Paragraph: Incorrect, I didn't mention the entire scheme, of falses bytes scattered around in a partially hidden but organised manner. So frequency analysis will lead false. And even if they open the source code, they would need to know the initial value of the text to find out how the false characters were organized.



Btw, this is going to be my completely unecessary method of keeping my programs with no source, everything is going to be an encrypted in a data file. The CD comes with a serial id that happens to be the A B C. When they run the program they enter the number, and if it's correct it translates the text file. Save them all as .pyc, runs them, then deletes them. And the decryptor will be fully obfuscated and compiled. I'm so good at being unecessary

Last edited by Sane; Jul 7th, 2005 at 7:54 PM.
Sane is offline   Reply With Quote
Old Jul 7th, 2005, 8:17 PM   #4
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,868
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
It would take a while, but I could create a loop that adds 0.0000001 to itself, and keeps testing the equation until it reaches approximately Y. *shrug* I might just do that ...


Edit:

That was considerably easier:

y = ?
a = ?
b = ?
c = ?


x = 0.000
TestY = x**a + x*b + c
while int(round(TestY*10)*10) != int(round(y*100)):
    x += 0.01
    TestY = x**a + x*b + c

print x

Last edited by Sane; Jul 7th, 2005 at 8:29 PM.
Sane is offline   Reply With Quote
Old Jul 7th, 2005, 9:51 PM   #5
skuinders
Hobbyist Programmer
 
skuinders's Avatar
 
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4 skuinders is on a distinguished road
in general, if you want to push a value through a function "backwards" you will need to have an inverse of the original function. an obvious illustration:
f(x) = e^x
g(x) = ln x
so you need to research methods for finding the inverse of polynomials. the quadratic formula is not relevant to what you are trying to do.
__________________
"A stupid man's report of what a clever man says can never be accurate, because he unconciously translates what he hears into something he can understand."
- B. Russell

http://web.bryant.edu/~srk2
skuinders is offline   Reply With Quote
Old Jul 7th, 2005, 10:10 PM   #6
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,868
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
HAH THIS WORKS GREAT!!! I bet you no one here can crack this!!!!! I challenge everyone here to actually try to get the correct CD Key.

Run this decoder program, and try to get the message to pop up by entering the correct CD key. Use any methods of Brute Force as you wish but you won't get it!

Encrypted_Code = """`ÿïÿ'¥ÿ-¥ÿ-6ÿ08ÿ¤ÿ4Vÿ*'ÿ+½ÿ38ÿ'ÿ+½ÿ38ÿùÿ+?ÿ5½ÿ3¤ÿ48ÿØÿ$8ÿ½ÿ3'ÿ+~ÿ.ÿ1¥ÿ-ïÿ'8ÿ~ÿ.ïÿ'½ÿ3½ÿ3Øÿ$‡ÿ)ïÿ'8ÿºÿ(Øÿ26ÿ0~ÿ.8ÿ~ÿ.ïÿ'¿ÿ8ÿÿØÿ$Yÿ/ïÿ'rÿ8ÿ®ÿïÿ'¤ÿ4$ÿ½ÿ38ÿ½ÿ3ïÿ'ïÿ'8ÿ'ÿ+ºÿ(8ÿØÿ$Yÿ/Eÿ96ÿ0Yÿ/ïÿ'8ÿØÿ$`ÿ&¤ÿ4?ÿ5Øÿ$¥ÿ-¥ÿ-Eÿ98ÿ‡ÿ)6ÿ0¤ÿ48ÿ'ÿ+¤ÿ4xÿ"""

import math,sys
class EG(object):
    def __init__(self,e,g,d):self.e=e;self.g=g;self.d=d     
    def D(self, TrF):
        print'Decrypting:';yUT=map(ord,TrF)
        for d in range(len(yUT)):
            if str(yUT[d])=='%s%s%s'%('2',['5','4','3','2','1'][int('0')],str(4+1)):yUT[d-1]=int(yUT[d-1])+((128+127)*(int(yUT[d+1])));yUT[d]='';yUT[d+1]=''
        for d in range(len(yUT)):
            for e in range(len(str(yUT[d]))):
                if int(str(yUT[d])[e])>4:
                    try:yUT[d+1]=''
                    except:pass
        yuI=' '
        while yuI:
            try:yUT.remove('')
            except:yuI=False
        KJjh=[]
        for item in yUT:
            try:
                y=int(str(item));a=self.e;b=self.g;c=self.d;x=0.000;Gh=x**a+x*b+c
                while int(round(Gh*10)*10)!=int(round(y*100)):x+=0.01;Gh=x**a+x*b+c
                KJjh.append(int(round(x)))
            except:pass
        yUT=map(chr,KJjh);return''.join(yUT)
hYh=raw_input('\n\nCD Key? (e.g. 1-1-259)\n');HhH=[]
for a in range(len(hYh)):
    try:
        if hYh[a-1]!='-'and hYh[a]=='-':HhH.append(a)
    except:
        if hYh[a]=='-':HhH.append(a)
try:a=int(hYh[:HhH[0]]);b=int(hYh[HhH[0]+1:HhH[1]]);c=int(hYh[HhH[1]+1:]);EG=EG(a,b,c)
except:raw_input('Invalid CD Key Format!');sys.exit()
try:d=EG.D(Encrypted_Code)
except:raw_input('Invalid CD Key!');sys.exit()
raw_input(d)

BWAHAHAHAHA
Sane is offline   Reply With Quote
Old Jul 8th, 2005, 12:50 AM   #7
HUmarMatt
Newbie
 
Join Date: Jul 2005
Posts: 0
Rep Power: 0 HUmarMatt is on a distinguished road
Man, I have such a generic name ... *sigh*
BTW, Sane, I'm a complete noob at programming, and I'm a new member here but damn that was easy, here's the first 8 words of it: 'Hello this is just a simple message from'
HUmarMatt is offline   Reply With Quote
Old Jul 8th, 2005, 1:01 AM   #8
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,868
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
OWNED!!

>.>
<.<

Errr good job, mind explaining how you did it so easily exactly? It would be better if it was closed-source. Did I miss out on some simple opening?
Sane is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:58 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC