x=5
iPtr=id(x)
iPtr=7
x=1
iPtr=id(x)
iPtr=5
print "\n*iPtr = "+str(iPtr)+"\n &x = "+str(id(x))
x=5
y=10
iPtr=None
print "Pointer points to: ",iPtr
iPtr=id(y)
print "Ptr now points to: ",iPtr
x=iPtr
print "The value of x is now",x
iPtr=15
print "The value of y is now",iPtr
def addTwoNumbers(x,y):
return x+y
x=0
y=0
x=int(raw_input("Enter first number:"))
y=int(raw_input("Enter second number:"))
print "Result is: ",addTwoNumbers(x,y)
def demoPassByValue(x):
x+=5
print "The value of x is:",x
x=0
x=int(raw_input("Enter a number:"))
demoPassByValue(x)
print "The original value of x did not change:",x
def demoPassByReference(x):
x+=5
print "The value of x is now",x
x=0
x=int(raw_input("Enter a number:"))
demoPassByReference(x)
iArray=[1,2,3,4,5]
iPtr=id(iArray)
print "Address of pointer: ",iPtr
print "First address of array: ",id(iArray[0])
print "Pointer points to: ",iArray[0]
print "First element of array contains",iArray[0]
def nameLength(name):
x=0
while(name[x] != '\0'):
x+=1;
return x
aName='\0'
aName=raw_input("Enter your first name: ")
aName=aName+'\0'
print "Your first name contains"
print str(nameLength(aName))+" characters"
def squareNumber(num):
for x in range(3):
num[x]=num[x]*num[x]
iNumbers=[2,4,6]
print "The current array value are:"
for x in range(3):
print iNumbers[x]
print "\n"
squareNumber(iNumbers)
print "The modified array values are :"
for x in range(3):
print iNumbers[x]
print "\n"
def printArgument(num):
print "Read only argument is: ",num
iNumber=5
printArgument(iNumber)
def printArray(num):
for x in range(3):
print num[x]
iNumbers=[2,4,6]
printArray(iNumbers)
def modifyArray(num):
for x in range(3):
num[x]=num[x]*num[x]
iNumbers=[2,4,6]
modifyArray(iNumbers)
import random
def encrypt(sMessage,random):
x=0
while(sMessage[x]):
sMessage+=str(random)
x+=1
x=0
print "Encrypted message is: "
while(sMessage[x]):
print sMessage[x]
x+=1
def decrypt(sMessage,random):
x=0
while(sMessage[x]):
sMessage[x]=sMessage[x]-str(random)
x+=1
x=0
while(sMessage[x]):
print sMessage[x]
x+=1
myString=range(21)
iSelection=0
iRand= (random.randint(1,4)%4)+1
while(iSelection != 4):
print "\n\n1\t Encrypt Clear Text\n"
print "2\tDecrypt Cipher Text\n"
print "3\tGenerate New Key\n"
print "4\tQuit\n"
iSelection=int(raw_input("\nSelect a Cryptography Option: "))
if(iSelection ==1):
myString=raw_input("\nEnter one word as clear text to encrypt: ")
encrypt(myString,iRand)
break
elif(iSelection==2):
myString=raw_input("\nEnter cipher text to decrypt: ")
decrypt(myString,iRand)
break
elif(iSelection==3):
iRand= (random.randrange(1,4,1)%4)+1
print "\nNew Key Generated\n"
break
else:
exit(0)