how to find an encrypted key?

Put your programming skills to the test in these challenges.

how to find an encrypted key?

Post by ghostheadx2 on Wed Jun 10, 2015 10:40 pm
([msg=88448]see how to find an encrypted key?[/msg])

So, I have this python file. I'm trying to make the key appear. I'm not asking for it decrypted, but I want to print the encrypted key. I'm wondering if I could do this by writing the key to another file so that when I open that file it appears. When I try to run it right now, I get:

Code: Select all
Usage: ZOR.py [encrypt/decrypt] [in_file] [out_file] [password]


Here is the file:

Code: Select all
#!/usr/bin/python

import sys

"""
Daedalus Corporation encryption script.
"""

def xor(input_data, key):
    result = ""
    for ch in input_data:
        result += chr(ord(ch) ^ key)

    return result

def encrypt(input_data, password):
    key = 0
    for ch in password:
        key ^= ((2 * ord(ch) + 3) & 0xff)

    return xor(input_data, key)

def decrypt(input_data, password):
    return encrypt(input_data, password)

def usage():
    print("Usage: %s [encrypt/decrypt] [in_file] [out_file] [password]" % sys.argv[0])
    exit()

def main():
    if len(sys.argv) < 5:
        usage()

    input_data = open(sys.argv[2], 'r').read()
    result_data = ""

    if sys.argv[1] == "encrypt":
        result_data = encrypt(input_data, sys.argv[4])
    elif sys.argv[1] == "decrypt":
        result_data = decrypt(input_data, sys.argv[4])
    else:
        usage()

    out_file = open(sys.argv[3], 'w')
    out_file.write(result_data)
    out_file.close()

main()



I feel like whatever I'm doing isn't working so I gave the original, unedited, file so that maybe someone could give me a hint. Here's the current hint:

The password gets reduced to a one byte XOR key. That's only 256 possible keys!


-- Wed Jun 10, 2015 10:51 pm --

I got it. I just need to get the XOR key. Then I can decrypt the key. How do I get the XOR key from a python file?
ghostheadx2
Contributor
Contributor
 
Posts: 728
Joined: Wed Nov 19, 2014 1:19 am
Blog: View Blog (0)


Re: how to find an encrypted key?

Post by Goatboy on Wed Jun 10, 2015 11:20 pm
([msg=88449]see Re: how to find an encrypted key?[/msg])

Here's a hint:

The password gets reduced to a one byte XOR key. That's only 256 possible keys!

Think about what this is saying. The key is one byte. A byte is 8 bits. There are 256 combinations of 8 bits, so there are 256 things that could be considered a single byte. As far as brute force goes, this is about as easy as it gets.
Assume that everything I say is or could be a lie.
User avatar
Goatboy
Expert
Expert
 
Posts: 2864
Joined: Mon Jul 07, 2008 9:35 pm
Blog: View Blog (0)


Re: how to find an encrypted key?

Post by ghostheadx2 on Thu Jun 11, 2015 3:00 pm
([msg=88466]see Re: how to find an encrypted key?[/msg])

But I don't know how to brute force.

-- Thu Jun 11, 2015 3:00 pm --

I guess I just have to Google "how to brute force" then?
ghostheadx2
Contributor
Contributor
 
Posts: 728
Joined: Wed Nov 19, 2014 1:19 am
Blog: View Blog (0)


Re: how to find an encrypted key?

Post by Goatboy on Fri Jun 12, 2015 12:13 am
([msg=88472]see Re: how to find an encrypted key?[/msg])

That might get you close, but do you know how XOR works? Do you know the difference between a "key", "plaintext", and "ciphertext"? Studying up on basic encryption would be a good start.
Assume that everything I say is or could be a lie.
User avatar
Goatboy
Expert
Expert
 
Posts: 2864
Joined: Mon Jul 07, 2008 9:35 pm
Blog: View Blog (0)


Re: how to find an encrypted key?

Post by ghostheadx2 on Sat Jun 13, 2015 10:47 pm
([msg=88525]see Re: how to find an encrypted key?[/msg])

ghostheadx2
Contributor
Contributor
 
Posts: 728
Joined: Wed Nov 19, 2014 1:19 am
Blog: View Blog (0)


Re: how to find an encrypted key?

Post by JackBurden on Sun Jun 14, 2015 12:24 am
([msg=88527]see Re: how to find an encrypted key?[/msg])

This a fun fairly easy programming challenge that will teach you the basics of XOR
https://projecteuler.net/problem=59 "XOR Decryption"
JackBurden
New User
New User
 
Posts: 1
Joined: Sun Jun 14, 2015 12:20 am
Blog: View Blog (0)


Re: how to find an encrypted key?

Post by sanddbox on Thu Jun 18, 2015 10:35 pm
([msg=88571]see Re: how to find an encrypted key?[/msg])

ghostheadx2 wrote:But I don't know how to brute force.

-- Thu Jun 11, 2015 3:00 pm --

I guess I just have to Google "how to brute force" then?


If every iPhone passcode was only 1 number long, how would you get into somebody's phone? Yes, you don't know their passcode, but it takes you 1 second to input a guess, and there's only 10 possible guesses...

Now imagine the same scenario, except there's 256 possible passwords, but you have this special device called a computer to do the guessing for you, and computers are fast, so each guess only takes around 10 milliseconds. The password would be easy to find, right?

I suspect you don't understand binary and binary operations (like XOR) well enough, otherwise the solution would be obvious. All you need to figure out is how to generate every possible solution, and then how to check each possibility to see if it's right.
Image

HTS User Composition:
95% Male
4.98% Female
.01% Monica
.01% Goat
User avatar
sanddbox
Expert
Expert
 
Posts: 2344
Joined: Sat Jul 04, 2009 5:20 pm
Blog: View Blog (0)


Re: how to find an encrypted key?

Post by ghostheadx2 on Fri Jun 19, 2015 2:24 am
([msg=88573]see Re: how to find an encrypted key?[/msg])

I don't understand them well enough. I have to read up on some stuff I guess. I'm finding cryptography tutorials to do so I'm getting on it.

-- Fri Jun 19, 2015 2:34 am --

would cryptography tutorials help?
ghostheadx2
Contributor
Contributor
 
Posts: 728
Joined: Wed Nov 19, 2014 1:19 am
Blog: View Blog (0)


Re: how to find an encrypted key?

Post by sanddbox on Sun Jun 21, 2015 8:59 pm
([msg=88602]see Re: how to find an encrypted key?[/msg])

To a certain extent, but "cryptography tutorials" is very vague. For this problem, you just need a basic grasp of programming, an understanding of binary (including operations like XOR), and knowledge of the meaning of the words "brute" and "force".
Image

HTS User Composition:
95% Male
4.98% Female
.01% Monica
.01% Goat
User avatar
sanddbox
Expert
Expert
 
Posts: 2344
Joined: Sat Jul 04, 2009 5:20 pm
Blog: View Blog (0)



Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests