New to Python; Trying a Hash

For the discussion of Perl, Python, Ruby, and PHP and other interpreted languages.

New to Python; Trying a Hash

Post by LostinCyberia on Thu Jul 26, 2012 12:48 am
([msg=68326]see New to Python; Trying a Hash[/msg])

Hello... first post on this great site! I was curious as to how to go about creating a simple little program to has individual or strings of characters. I'm sure there are numerous ways to do this, but I want something simple to start with, then I can add and modify ways later on as I explore.. Any idea's or links to such feats?
Remember what the dor-mouse said; Feed your head.
User avatar
LostinCyberia
New User
New User
 
Posts: 13
Joined: Wed Jul 25, 2012 9:42 am
Blog: View Blog (0)


Re: New to Python; Trying a Hash

Post by wan26 on Fri Jul 27, 2012 6:53 am
([msg=68356]see Re: New to Python; Trying a Hash[/msg])

A good start would be to look at more basic algorithms that you can visualize working in a program. Probably the caesar cipher would be a good start.

-- Fri Jul 27, 2012 7:13 am --

And because I like Python, I wrote a quick example for you

Code: Select all
# here you go

shift = 2

ans = raw_input("enter letter " )

#print ans[]

new =  ord(ans) + shift
print chr(new)


It works on one letter, perhaps you could change it and make it better
User avatar
wan26
Experienced User
Experienced User
 
Posts: 91
Joined: Sun Jan 22, 2012 6:46 pm
Blog: View Blog (0)


Re: New to Python; Trying a Hash

Post by LostinCyberia on Sat Jul 28, 2012 12:48 pm
([msg=68408]see Re: New to Python; Trying a Hash[/msg])

Thanks for your reply! I came up with this one. It's just a numerical cipher

# A Simple Casser Cipher

shift = 4

outcome = input ("Enter Value Here ")

print "The Ciphered text is: "
print outcome + shift
Remember what the dor-mouse said; Feed your head.
User avatar
LostinCyberia
New User
New User
 
Posts: 13
Joined: Wed Jul 25, 2012 9:42 am
Blog: View Blog (0)


Re: New to Python; Trying a Hash

Post by wan26 on Sat Jul 28, 2012 2:03 pm
([msg=68409]see Re: New to Python; Trying a Hash[/msg])

I like what you did with the numbers but maybe something that starts to get more practical would work too, I changed my original slightly:

Code: Select all
text = 'abcdefhijklmopqrstuvwxyz'
new = [''] * len(text)
shift = 4

for i in range (0, len(text)):
    new[i] = chr(ord(text[i]) + shift)

print new


Trying this in c++ is interesting too,
User avatar
wan26
Experienced User
Experienced User
 
Posts: 91
Joined: Sun Jan 22, 2012 6:46 pm
Blog: View Blog (0)



Return to Interpreted Languages

Who is online

Users browsing this forum: No registered users and 0 guests