python encryption - 5 char only

Questions about programming languages and debugging
Post Reply
p99
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 291
Joined: 14 Oct 2006, 16:00
17
Location: Some hippy's van
Contact:

python encryption - 5 char only

Post by p99 »

I made this today. There is a story behind it but I don't feel like explaining right now. So here.

I know it lacks functionality. A lot, but i did this all on my own. Which is big for me. my first encryption program. It doesn't decrypt btw.


I had to prove to my friend that I could produce better encryption than him even though he pwns me in programming. So I worked ALL day on this from the time I got home from school till 10 PM.

It will only encode 5 charector lowercase words.
But check it out anyways.

It's written fully in python. Later versions will allow for encryption with any length line. That's my short term goal. And to come up with a much better equation and to decrypt it.

All comments and criticism welcome

Code: Select all

o_txt = raw_input("What is the string you wish to encrypt?: \n")
mod_txt = o_txt[:0] + o_txt[1:2] + o_txt[3:4] + o_txt[0:1] + o_txt[2:3] + o_txt[4:5]

mod2_txt_val = 1
mod2_txt_val2 = 1
mod2_txt_val3 = 1
mod2_txt_val4 = 1
mod2_txt_val5 = 1
mod2_txt_val6 = 1

if o_txt[:0] == 'a':
    mod2_txt_val = 5
elif o_txt[:0] == 'b':
    mod2_txt_val = 15
elif o_txt[:0] == 'c':
    mod2_txt_val = 25
elif o_txt[:0] == 'd':
    mod2_txt_val = 35
elif o_txt[:0] == 'e':
    mod2_txt_val = 45
elif o_txt[:0] == 'f':
    mod2_txt_val = 55
elif o_txt[:0] == 'g':
    mod2_txt_val = 65
elif o_txt[:0] == 'h':
    mod2_txt_val = 75
elif o_txt[:0] == 'i':
    mod2_txt_val = 85
elif o_txt[:0] == 'j':
    mod2_txt_val = 95
elif o_txt[:0] == 'k':
    mod2_txt_val = 105
elif o_txt[:0] == 'l':
    mod2_txt_val = 115
elif o_txt[:0] == 'm':
    mod2_txt_val = 125
elif o_txt[:0] == 'n':
    mod2_txt_val = 135
elif o_txt[:0] == 'o':
    mod2_txt_val = 145
elif o_txt[:0] == 'p':
    mod2_txt_val = 155
elif o_txt[:0] == 'q':
    mod2_txt_val = 165
elif o_txt[:0] == 'r':
    mod2_txt_val = 175
elif o_txt[:0] == 's':
    mod2_txt_val = 185
elif o_txt[:0] == 't':
    mod2_txt_val = 195
elif o_txt[:0] == 'u':
    mod2_txt_val = 205
elif o_txt[:0] == 'v':
    mod2_txt_val = 215
elif o_txt[:0] == 'w':
    mod2_txt_val = 225
elif o_txt[:0] == 'x':
    mod2_txt_val = 235
elif o_txt[:0] == 'y':
    mod2_txt_val = 245
elif o_txt[:0] == 'z':
    mod2_txt_val = 255

if o_txt[1:2] == 'a':
    mod2_txt_val2 = 3
    print "first #2"
elif o_txt[1:2] == 'b':
    mod2_txt_val2 = 13
elif o_txt[1:2] == 'c':
    mod2_txt_val2 = 23
elif o_txt[1:2] == 'd':
    mod2_txt_val2 = 33
elif o_txt[1:2] == 'e':
    mod2_txt_val2 = 43
elif o_txt[1:2] == 'f':
    mod2_txt_val2 = 53
elif o_txt[1:2] == 'g':
    mod2_txt_val2 = 63
elif o_txt[1:2] == 'h':
    mod2_txt_val2 = 73
elif o_txt[1:2] == 'i':
    mod2_txt_val2 = 83
elif o_txt[1:2] == 'j':
    mod2_txt_val2 = 93
elif o_txt[1:2] == 'k':
    mod2_txt_val2 = 103
elif o_txt[1:2] == 'l':
    mod2_txt_val2 = 113
elif o_txt[1:2] == 'm':
    mod2_txt_val2 = 123
elif o_txt[1:2] == 'n':
    mod2_txt_val2 = 133
elif o_txt[1:2] == 'o':
    mod2_txt_val2 = 143
elif o_txt[1:2] == 'p':
    mod2_txt_val2 = 153
elif o_txt[1:2] == 'q':
    mod2_txt_val2 = 163
elif o_txt[1:2] == 'r':
    mod2_txt_val2 = 173
elif o_txt[1:2] == 's':
    mod2_txt_val2 = 183
elif o_txt[1:2] == 't':
    mod2_txt_val2 = 193
elif o_txt[1:2] == 'u':
    mod2_txt_val2 = 203
elif o_txt[1:2] == 'v':
    mod2_txt_val2 = 213
elif o_txt[1:2] == 'w':
    mod2_txt_val2 = 223
elif o_txt[1:2] == 'x':
    mod2_txt_val2 = 233
elif o_txt[1:2] == 'y':
    mod2_txt_val2 = 243
elif o_txt[1:2] == 'z':
    mod2_txt_val2 = 253

if o_txt[3:4] == 'a':
    mod2_txt_val3 = 2
    print "first #3"
elif o_txt[3:4] == 'b':
    mod2_txt_val3 = 12
elif o_txt[3:4] == 'c':
    mod2_txt_val3 = 22
elif o_txt[3:4] == 'd':
    mod2_txt_val3 = 32
elif o_txt[3:4] == 'e':
    mod2_txt_val3 = 42
elif o_txt[3:4] == 'f':
    mod2_txt_val3 = 52
elif o_txt[3:4] == 'g':
    mod2_txt_val3 = 62
elif o_txt[3:4] == 'h':
    mod2_txt_val3 = 72
elif o_txt[3:4] == 'i':
    mod2_txt_val3 = 82
elif o_txt[3:4] == 'j':
    mod2_txt_val3 = 92
elif o_txt[3:4] == 'k':
    mod2_txt_val3 = 102
elif o_txt[3:4] == 'l':
    mod2_txt_val3 = 112
elif o_txt[3:4] == 'm':
    mod2_txt_val3 = 122
elif o_txt[3:4] == 'n':
    mod2_txt_val3 = 132
elif o_txt[3:4] == 'o':
    mod2_txt_val3 = 142
elif o_txt[3:4] == 'p':
    mod2_txt_val3 = 152
elif o_txt[3:4] == 'q':
    mod2_txt_val3 = 162
elif o_txt[3:4] == 'r':
    mod2_txt_val3 = 172
elif o_txt[3:4] == 's':
    mod2_txt_val3 = 182
elif o_txt[3:4] == 't':
    mod2_txt_val3 = 192
elif o_txt[3:4] == 'u':
    mod2_txt_val3 = 202
elif o_txt[3:4] == 'v':
    mod2_txt_val3 = 212
elif o_txt[3:4] == 'w':
    mod2_txt_val3 = 222
elif o_txt[3:4] == 'x':
    mod2_txt_val3 = 232
elif o_txt[3:4] == 'y':
    mod2_txt_val3 = 242
elif o_txt[3:4] == 'z':
    mod2_txt_val3 = 252

if o_txt[0:1] == 'a':
    mod2_txt_val4 = 9
    print "first"
elif o_txt[0:1] == 'b':
    mod2_txt_val4 = 19
elif o_txt[0:1] == 'c':
    mod2_txt_val4 = 29
elif o_txt[0:1] == 'd':
    mod2_txt_val4 = 39
elif o_txt[0:1] == 'e':
    mod2_txt_val4 = 49
elif o_txt[0:1] == 'f':
    mod2_txt_val4 = 59
elif o_txt[0:1] == 'g':
    mod2_txt_val4 = 69
elif o_txt[0:1] == 'h':
    mod2_txt_val4 = 79
elif o_txt[0:1] == 'i':
    mod2_txt_val4 = 89
elif o_txt[0:1] == 'j':
    mod2_txt_val4 = 99
elif o_txt[0:1] == 'k':
    mod2_txt_val4 = 109
elif o_txt[0:1] == 'l':
    mod2_txt_val4 = 119
elif o_txt[0:1] == 'm':
    mod2_txt_val4 = 129
elif o_txt[0:1] == 'n':
    mod2_txt_val4 = 139
elif o_txt[0:1] == 'o':
    mod2_txt_val4 = 149
elif o_txt[0:1] == 'p':
    mod2_txt_val4 = 159
elif o_txt[0:1] == 'q':
    mod2_txt_val4 = 169
elif o_txt[0:1] == 'r':
    mod2_txt_val4 = 179
elif o_txt[0:1] == 's':
    mod2_txt_val4 = 189
elif o_txt[0:1] == 't':
    mod2_txt_val4 = 199
elif o_txt[0:1] == 'u':
    mod2_txt_val4 = 209
elif o_txt[0:1] == 'v':
    mod2_txt_val4 = 219
elif o_txt[0:1] == 'w':
    mod2_txt_val4 = 229
elif o_txt[0:1] == 'x':
    mod2_txt_val4 = 239
elif o_txt[0:1] == 'y':
    mod2_txt_val4 = 249
elif o_txt[0:1] == 'z':
    mod2_txt_val4 = 259

if o_txt[2:3] == 'a':
    mod2_txt_val5 = mod2_txt_val3 * 4
    print "first"
elif o_txt[2:3] == 'b':
    mod2_txt_val5 = mod2_txt_val3 * 14
elif o_txt[2:3] == 'c':
    mod2_txt_val5 = mod2_txt_val3 * 24
elif o_txt[2:3] == 'd':
    mod2_txt_val5 = mod2_txt_val3 * 34
elif o_txt[2:3] == 'e':
    mod2_txt_val5 = mod2_txt_val3 * 44
elif o_txt[2:3] == 'f':
    mod2_txt_val5 = mod2_txt_val3 * 54
elif o_txt[2:3] == 'g':
    mod2_txt_val5 = mod2_txt_val3 * 64
elif o_txt[2:3] == 'h':
    mod2_txt_val5 = mod2_txt_val3 * 74
elif o_txt[2:3] == 'i':
    mod2_txt_val5 = mod2_txt_val3 * 84
elif o_txt[2:3] == 'j':
    mod2_txt_val5 = mod2_txt_val3 * 94
elif o_txt[2:3] == 'k':
    mod2_txt_val5 = mod2_txt_val3 * 104
elif o_txt[2:3] == 'l':
    mod2_txt_val5 = mod2_txt_val3 * 114
elif o_txt[2:3] == 'm':
    mod2_txt_val5 = mod2_txt_val3 * 124
elif o_txt[2:3] == 'n':
    mod2_txt_val5 = mod2_txt_val3 * 134
elif o_txt[2:3] == 'o':
    mod2_txt_val5 = mod2_txt_val3 * 144
elif o_txt[2:3] == 'p':
    mod2_txt_val5 = mod2_txt_val3 * 154
elif o_txt[2:3] == 'q':
    mod2_txt_val5 = mod2_txt_val3 * 164
elif o_txt[2:3] == 'r':
    mod2_txt_val5 = mod2_txt_val3 * 174
elif o_txt[2:3] == 's':
    mod2_txt_val5 = mod2_txt_val3 * 184
elif o_txt[2:3] == 't':
    mod2_txt_val5 = mod2_txt_val3 * 194
elif o_txt[2:3] == 'u':
    mod2_txt_val5 = mod2_txt_val3 * 204
elif o_txt[2:3] == 'v':
    mod2_txt_val5 = mod2_txt_val3 * 214
elif o_txt[2:3] == 'w':
    mod2_txt_val5 = mod2_txt_val3 * 224
elif o_txt[2:3] == 'x':
    mod2_txt_val5 = mod2_txt_val3 * 234
elif o_txt[2:3] == 'y':
    mod2_txt_val5 = mod2_txt_val3 * 244
elif o_txt[2:3] == 'z':
    mod2_txt_val5 = mod2_txt_val3 * 254

if o_txt[4:5] == 'a':
    mod2_txt_val6 = 13
    print "first"
elif o_txt[4:5] == 'b':
    mod2_txt_val6 = 12
elif o_txt[4:5] == 'c':
    mod2_txt_val6 = 11
elif o_txt[4:5] == 'd':
    mod2_txt_val6 = 10
elif o_txt[4:5] == 'e':
    mod2_txt_val6 = 9
elif o_txt[4:5] == 'f':
    mod2_txt_val6 = 8
elif o_txt[4:5] == 'g':
    mod2_txt_val6 = 7
elif o_txt[4:5] == 'h':
    mod2_txt_val6 = 6
elif o_txt[4:5] == 'i':
    mod2_txt_val6 = 5
elif o_txt[4:5] == 'j':
    mod2_txt_val6 = 4
elif o_txt[4:5] == 'k':
    mod2_txt_val6 = 3
elif o_txt[4:5] == 'l':
    mod2_txt_val6 = 2
elif o_txt[4:5] == 'm':
    mod2_txt_val6 = 1
elif o_txt[4:5] == 'n':
    mod2_txt_val6 = 9
elif o_txt[4:5] == 'o':
    mod2_txt_val6 = 1
elif o_txt[4:5] == 'p':
    mod2_txt_val6 = 2
elif o_txt[4:5] == 'q':
    mod2_txt_val6 = 3
elif o_txt[4:5] == 'r':
    mod2_txt_val6 = 4
elif o_txt[4:5] == 's':
    mod2_txt_val6 = 5
elif o_txt[4:5] == 't':
    mod2_txt_val6 = 6
elif o_txt[4:5] == 'u':
    mod2_txt_val6 = 7
elif o_txt[4:5] == 'v':
    mod2_txt_val6 = 8
elif o_txt[4:5] == 'w':
    mod2_txt_val6 = 9
elif o_txt[4:5] == 'x':
    mod2_txt_val6 = 10
elif o_txt[4:5] == 'y':
    mod2_txt_val6 = 11
elif o_txt[4:5] == 'z':
    mod2_txt_val6 = 12

mod2_txt = mod2_txt_val * mod2_txt_val2 * mod2_txt_val3 * mod2_txt_val4 * mod2_txt_val5 * mod2_txt_val6
print "Before being converted to #'s"
print mod_txt
print "\nAfter being converted to numbers and math applied"
print mod2_txt
print o_txt

pseudo_opcode
cyber messiah
cyber messiah
Posts: 1201
Joined: 30 Apr 2006, 16:00
17
Location: 127.0.0.1

Post by pseudo_opcode »

hmm, i dont know python so i cant comment on efficiency, niether did i understand the algorithm, but what i can see is that you only asked user to enter the string to encrypt, where's the key?

Encryption without a key in not ecryption, its encoding.

p99
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 291
Joined: 14 Oct 2006, 16:00
17
Location: Some hippy's van
Contact:

Post by p99 »

Yeah this is what i'm getting. I haven't worked out how to unencode yet. I honestly haven't even tried. I'm trying to shorten my code and get much more flexability out of it.

depending on the letter of any char it will get a value.

then I mulitply each together.

1*2*3*4*5*6 = the final number output.

python is really simple, but I see what your saying. Everyone was telling me encryption is modifying the actual file structure while ecoding was modifying the contents of a file.

But my brain is fried because I haven't programmed in months. So... yeah. I'm going to make it so the program creates a key.

pseudo_opcode
cyber messiah
cyber messiah
Posts: 1201
Joined: 30 Apr 2006, 16:00
17
Location: 127.0.0.1

Post by pseudo_opcode »

Its not like the program should give you a key but also you can enter a key which is used to encrypt and decrypt the message or whatever. Otherwise why would encryption be so reliable if everyone knows say the algorithm of say triple blowfish encryption, anyone would make the program to decipher it. Thats why cryptography is considered difficult

and yes both file and message can be ecrypted or encoded, i wonder who is that "Everyone"??

Also its not that i dont know python coz its difficult, i dont want to learn it simply coz i dont need to.

(oh my 400th post!!! w00t!!! where's my prize? :D )

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Post by bad_brain »

pseudo_opcode wrote:oh my 400th post!!! w00t!!! where's my prize? :D
ummm...let's see....castle of gold..nah, that's for 1750 posts....ah, here it is:
400 posts = male stripper...he will arrive soon, have fun! :lol:

alien100
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 693
Joined: 25 Sep 2006, 16:00
17
Location: Spartan HQ
Contact:

Post by alien100 »

lol :lol: a male stripper funny
[img]http://img127.imageshack.us/img127/9128/sig3copyyybq4.jpg[/img]

pseudo_opcode
cyber messiah
cyber messiah
Posts: 1201
Joined: 30 Apr 2006, 16:00
17
Location: 127.0.0.1

Post by pseudo_opcode »

duh... where's the resignation template?? :roll:

@p99 you might also want to learn a few things which may help in encryption programs, like permutations, compression, rotation and all,for both keys and data.

Just grab an open source encryption library and try to use that, and later you can try and create your own.

p99
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 291
Joined: 14 Oct 2006, 16:00
17
Location: Some hippy's van
Contact:

Post by p99 »

Yeah, about the only thing I could think of yesterday was the "picket fence" method.

Code: Select all

handle

Code: Select all

h n l
 a d e

Code: Select all

hnlade
Kind of like that. I also used substitution and used math.
But yeah i'm definatly going to be reading up and trying to improve my coding skills. I know my code is much longer than it needs to be. I just can't quite figure out how to shorten it.

pseudo_opcode
cyber messiah
cyber messiah
Posts: 1201
Joined: 30 Apr 2006, 16:00
17
Location: 127.0.0.1

Post by pseudo_opcode »

*tip* for python skills, maboroshi is person to look for :wink:

p99
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 291
Joined: 14 Oct 2006, 16:00
17
Location: Some hippy's van
Contact:

Post by p99 »

Alright thanks.

User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

Re Encryption

Post by maboroshi »

this may help in shortening your code

4.2 for Statements

The for statement in Python differs a bit from what you may be used to in C or Pascal. Rather than always iterating over an arithmetic progression of numbers (like in Pascal), or giving the user the ability to define both the iteration step and halting condition (as C), Python's for statement iterates over the items of any sequence (a list or a string), in the order that they appear in the sequence. For example (no pun intended):

Code: Select all

>>> # Measure some strings:
... a = ['cat', 'window', 'defenestrate']
>>> for x in a:
...     print x, len(x)
... 
cat 3
window 6
defenestrate 12
It is not safe to modify the sequence being iterated over in the loop (this can only happen for mutable sequence types, such as lists). If you need to modify the list you are iterating over (for example, to duplicate selected items) you must iterate over a copy. The slice notation makes this particularly convenient:

Code: Select all

>>> for x in a[:]: # make a slice copy of the entire list
...    if len(x) > 6: a.insert(0, x)
... 
>>> a
['defenestrate', 'cat', 'window', 'defenestrate']
taken from

http://docs.python.org/tut/node6.html

p99
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 291
Joined: 14 Oct 2006, 16:00
17
Location: Some hippy's van
Contact:

Post by p99 »

Alright that helps a whole lot. once I learn how to use Split() I can make a string inputted by a user into a list. Well I think anyways.

Post Reply