SlideShare a Scribd company logo
#PROJECT 2
#Kevin Zhang and Sijia Sun
#Raymond Wong
#Section 3
#Encrypting Messages
#STEP 1
def shortenKey(raw_key):
index = 0
short_key = ''
for ch in raw_key:
newIndex = 0
furthestIndex = -1
for newch in raw_key:
if newch == ch and index != newIndex:
furthestIndex = newIndex
newIndex += 1
if furthestIndex == -1 or furthestIndex < index:
short_key += ch
index += 1
return short_key
def generateKey(raw_key):
key = ''
for ch in shortenKey(raw_key):
count = 0
for newch in shortenKey(raw_key):
if newch < ch:
count = count + 1
key += str(count+1)
return key
#STEP 2
import random
def toPlaintext(s, keyLength):
intermediate = ''
for c in s:
if ord(c) > 64 and ord(c) < 91:
intermediate += c
plaintext = intermediate
for i in range((keyLength - len(plaintext) % keyLength) % keyLength):
plaintext += chr(random.randint(65, 90))
return plaintext
# STEP 3
def columnar(plaintext, key):
ciphertext = ''
for i in range(len(str(key))):
ki = 0
for k in str(key):
if str(k) == str(i + 1):
pi = 0
for p in plaintext:
if pi % len(str(key)) == ki:
ciphertext += p
pi += 1
ki += 1
return ciphertext
# STEP 4
def encryptColumnar(s, raw_key):
key = generateKey(raw_key)
plaintext = toPlaintext(s, len(key))
return columnar(plaintext, key)
input_s = input('Enter the message: ')
input_key = input('Enter the raw key for columnar transposition: ')
print encryptColumnar(input_s, input_key)
project 3
#Kevin Zhang and Sijia Sun
#Raymond Wong
#Section 3
#Creating a Dictionary of Constellations and Stars
def starSetup():
newfile=open('starfile.txt','r')
s=newfile.readlines()
newfile.close()
news=[]
seplst=''
dictStar={}
for i in range(len(s)):
news.append(s[i].strip('n')) #eliminate n in each string
for j in range(len(news)):
seplst=news[j]
seplst=seplst.split() #eliminate all spaces
tup=(float(seplst[1]),float(seplst[2])) #create tuple
dictStar[seplst[0]]=tup #assign each key with a value in dict
return dictStar
def starData(starName,dictStar): #test if starName is in dictStar
if starName in dictStar:
return dictStar[starName] #if true, return value for starName
else:
return 'Not found in dictStar'
def starDistance(low,high):
dictStar=starSetup()
for key in dictStar.keys(): #using for loop to get every key in dictStar
if (dictStar[key][0]> low) and (dictStar[key][0]<high): #test for the conditions of Distance
print (key)
def starAPPVM(low,high):
dictStar=starSetup()
for key in dictStar.keys():
if (dictStar[key][1]> low) and (dictStar[key][1]<high):#test for the conditions of APPVM
print (key)
def starAvs(myDict): #for test procedure, we use starAvs(starSetup())
#G0
G0=[]
disG0=0
avgG0=0.0
for key in myDict.keys():
if (myDict[key][1]> 0.0) and (myDict[key][1]<=0.50): #test for the range from 0.0 to 0.5
G0.append(key) # add starname into G0 list
for i in range(len(G0)): #calculate total distance for G0
value=myDict[G0[i]]
disG0+=value[0]
avgG0=disG0/len(G0)
print('The mean distance of the stars in dictStar with 0.0 < APPVM <= 0.5 is '+str(avgG0))
#G1
#Kevin Zhang and Sijia Sun
#Raymond Wong
#Section 3
#Project 4
#Creating an Slideshow Window Program
from cImage import *
myWin = ImageWin("SlideShow", 400, 350) #opens window with dimensions 400x350
bottomBar = FileImage('/cs/student/kqzhang/cs8/p4images/bottom_bar.gif')
firstImage = FileImage('/cs/student/kqzhang/cs8/p4images/picture0.gif')
firstImage.draw(myWin)
bottomBar.setPosition(0,300)
bottomBar.draw(myWin)
def imageChange(i):
change = myWin.getMouse()
#print(change)
if change[0] in range(20, 60):
if change[1] in range(305, 345):
#print('left')
i = (i-1)%len(acc)
acc[i].draw(myWin)
elif change[0] in range(340,380):
if change[1] in range(305,345):
i = (i+1)%len(acc)
acc[i].draw(myWin)
elif change[0] in range(180, 220):
if change[1] in range(305,345):
myWin.exitOnClick()
return i
acc = []
def album(n): #input as 'n'
for img in range(0, n):
imgClxn = FileImage('/cs/student/kqzhang/cs8/p4images/picture' + str(img) + '.gif')
acc.append(imgClxn)
i = 0
while True:
i = imageChange(i)
album(7)
#Kevin Zhang and Sijia Sun
#Raymond Wong
#Section 3
#Project 4
#Creating an Slideshow Window Program
from cImage import *
myWin = ImageWin("SlideShow", 400, 350) #opens window with dimensions 400x350
bottomBar = FileImage('/cs/student/kqzhang/cs8/p4images/bottom_bar.gif')
firstImage = FileImage('/cs/student/kqzhang/cs8/p4images/picture0.gif')
firstImage.draw(myWin)
bottomBar.setPosition(0,300)
bottomBar.draw(myWin)
def imageChange(i):
change = myWin.getMouse()
#print(change)
if change[0] in range(20, 60):
if change[1] in range(305, 345):
#print('left')
i = (i-1)%len(acc)
acc[i].draw(myWin)
elif change[0] in range(340,380):
if change[1] in range(305,345):
i = (i+1)%len(acc)
acc[i].draw(myWin)
elif change[0] in range(180, 220):
if change[1] in range(305,345):
myWin.exitOnClick()
return i
acc = []
def album(n): #input as 'n'
for img in range(0, n):
imgClxn = FileImage('/cs/student/kqzhang/cs8/p4images/picture' + str(img) + '.gif')
acc.append(imgClxn)
i = 0
while True:
i = imageChange(i)
album(7)

More Related Content

PDF
Dart - en ny platform til webudvikling af Rico Wind, Google
PPTX
Conditional Statementfinal PHP 02
PPTX
Introducing to Asynchronous Programming
PDF
Voce Tem Orgulho Do Seu Codigo
PDF
Main Form Number To Word
PDF
Asssignment2
PPTX
From clever code to better code
PDF
What Have The Properties Ever Done For Us
Dart - en ny platform til webudvikling af Rico Wind, Google
Conditional Statementfinal PHP 02
Introducing to Asynchronous Programming
Voce Tem Orgulho Do Seu Codigo
Main Form Number To Word
Asssignment2
From clever code to better code
What Have The Properties Ever Done For Us

What's hot (20)

PDF
Legacy codesmalltalk
DOCX
C programs
DOCX
C-Sharp Arithmatic Expression Calculator
PDF
RSpec matchers
PPTX
利用Init connect做mysql clients stat 用户审计
PDF
Property-based testing
PPT
ALL BASIC SQL SERVER QUERY
DOCX
C++ program: All tasks .cpp
RTF
project3
PDF
Extending Structured Streaming Made Easy with Algebra with Erik Erlandson
PDF
The Ring programming language version 1.2 book - Part 55 of 84
DOC
Ip project
PDF
Is writing performant code too expensive?
PDF
Building Functional Islands
PPTX
LINQ Internals - STLDODN
PDF
Spock and Geb in Action
PDF
Clojure functions examples
PDF
The Ring programming language version 1.5.1 book - Part 63 of 180
PDF
Regexes and-performance-testing
PPTX
ES6(ES2015) is beautiful
Legacy codesmalltalk
C programs
C-Sharp Arithmatic Expression Calculator
RSpec matchers
利用Init connect做mysql clients stat 用户审计
Property-based testing
ALL BASIC SQL SERVER QUERY
C++ program: All tasks .cpp
project3
Extending Structured Streaming Made Easy with Algebra with Erik Erlandson
The Ring programming language version 1.2 book - Part 55 of 84
Ip project
Is writing performant code too expensive?
Building Functional Islands
LINQ Internals - STLDODN
Spock and Geb in Action
Clojure functions examples
The Ring programming language version 1.5.1 book - Part 63 of 180
Regexes and-performance-testing
ES6(ES2015) is beautiful
Ad

Similar to cs8project (20)

PDF
A Few of My Favorite (Python) Things
PPTX
Python.pptx
PPTX
第二讲 Python基礎
PPTX
第二讲 预备-Python基礎
PDF
Python Lab Manual for First year Engineering students
DOCX
Basic python laboratoty_ PSPP Manual .docx
PDF
PyLecture4 -Python Basics2-
PDF
python_lab_manual_final (1).pdf
PDF
Xi CBSE Computer Science lab programs
PDF
DOC333-2023-Sep-pythonprogramming-Lec04.pdf
PDF
Python Fundamentals - Basic
PDF
python practicals-solution-2019-20-class-xii.pdf
DOCX
Python lab manual all the experiments are available
PDF
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
PPTX
ANSHUL RANA - PROGRAM FILE.pptx
DOCX
python file for easy way practicle programs
PDF
Beautiful python - PyLadies
PDF
Python for High School Programmers
PDF
Raspberry Pi - Lecture 5 Python for Raspberry Pi
PDF
25 MARCH1 list, generator.pdf list generator
A Few of My Favorite (Python) Things
Python.pptx
第二讲 Python基礎
第二讲 预备-Python基礎
Python Lab Manual for First year Engineering students
Basic python laboratoty_ PSPP Manual .docx
PyLecture4 -Python Basics2-
python_lab_manual_final (1).pdf
Xi CBSE Computer Science lab programs
DOC333-2023-Sep-pythonprogramming-Lec04.pdf
Python Fundamentals - Basic
python practicals-solution-2019-20-class-xii.pdf
Python lab manual all the experiments are available
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
ANSHUL RANA - PROGRAM FILE.pptx
python file for easy way practicle programs
Beautiful python - PyLadies
Python for High School Programmers
Raspberry Pi - Lecture 5 Python for Raspberry Pi
25 MARCH1 list, generator.pdf list generator
Ad

cs8project

  • 1. #PROJECT 2 #Kevin Zhang and Sijia Sun #Raymond Wong #Section 3 #Encrypting Messages #STEP 1 def shortenKey(raw_key): index = 0 short_key = '' for ch in raw_key: newIndex = 0 furthestIndex = -1 for newch in raw_key: if newch == ch and index != newIndex: furthestIndex = newIndex newIndex += 1 if furthestIndex == -1 or furthestIndex < index: short_key += ch index += 1 return short_key def generateKey(raw_key): key = '' for ch in shortenKey(raw_key): count = 0 for newch in shortenKey(raw_key): if newch < ch: count = count + 1 key += str(count+1) return key #STEP 2 import random def toPlaintext(s, keyLength): intermediate = '' for c in s: if ord(c) > 64 and ord(c) < 91: intermediate += c plaintext = intermediate for i in range((keyLength - len(plaintext) % keyLength) % keyLength): plaintext += chr(random.randint(65, 90)) return plaintext # STEP 3
  • 2. def columnar(plaintext, key): ciphertext = '' for i in range(len(str(key))): ki = 0 for k in str(key): if str(k) == str(i + 1): pi = 0 for p in plaintext: if pi % len(str(key)) == ki: ciphertext += p pi += 1 ki += 1 return ciphertext # STEP 4 def encryptColumnar(s, raw_key): key = generateKey(raw_key) plaintext = toPlaintext(s, len(key)) return columnar(plaintext, key) input_s = input('Enter the message: ') input_key = input('Enter the raw key for columnar transposition: ') print encryptColumnar(input_s, input_key) project 3 #Kevin Zhang and Sijia Sun #Raymond Wong
  • 3. #Section 3 #Creating a Dictionary of Constellations and Stars def starSetup(): newfile=open('starfile.txt','r') s=newfile.readlines() newfile.close() news=[] seplst='' dictStar={} for i in range(len(s)): news.append(s[i].strip('n')) #eliminate n in each string for j in range(len(news)): seplst=news[j] seplst=seplst.split() #eliminate all spaces tup=(float(seplst[1]),float(seplst[2])) #create tuple dictStar[seplst[0]]=tup #assign each key with a value in dict return dictStar def starData(starName,dictStar): #test if starName is in dictStar if starName in dictStar: return dictStar[starName] #if true, return value for starName else: return 'Not found in dictStar' def starDistance(low,high): dictStar=starSetup() for key in dictStar.keys(): #using for loop to get every key in dictStar if (dictStar[key][0]> low) and (dictStar[key][0]<high): #test for the conditions of Distance print (key) def starAPPVM(low,high): dictStar=starSetup() for key in dictStar.keys(): if (dictStar[key][1]> low) and (dictStar[key][1]<high):#test for the conditions of APPVM print (key) def starAvs(myDict): #for test procedure, we use starAvs(starSetup()) #G0 G0=[] disG0=0 avgG0=0.0 for key in myDict.keys(): if (myDict[key][1]> 0.0) and (myDict[key][1]<=0.50): #test for the range from 0.0 to 0.5 G0.append(key) # add starname into G0 list
  • 4. for i in range(len(G0)): #calculate total distance for G0 value=myDict[G0[i]] disG0+=value[0] avgG0=disG0/len(G0) print('The mean distance of the stars in dictStar with 0.0 < APPVM <= 0.5 is '+str(avgG0)) #G1
  • 5. #Kevin Zhang and Sijia Sun #Raymond Wong #Section 3 #Project 4 #Creating an Slideshow Window Program from cImage import * myWin = ImageWin("SlideShow", 400, 350) #opens window with dimensions 400x350 bottomBar = FileImage('/cs/student/kqzhang/cs8/p4images/bottom_bar.gif') firstImage = FileImage('/cs/student/kqzhang/cs8/p4images/picture0.gif') firstImage.draw(myWin) bottomBar.setPosition(0,300) bottomBar.draw(myWin) def imageChange(i): change = myWin.getMouse() #print(change) if change[0] in range(20, 60): if change[1] in range(305, 345): #print('left') i = (i-1)%len(acc) acc[i].draw(myWin) elif change[0] in range(340,380): if change[1] in range(305,345): i = (i+1)%len(acc) acc[i].draw(myWin) elif change[0] in range(180, 220): if change[1] in range(305,345): myWin.exitOnClick() return i acc = [] def album(n): #input as 'n' for img in range(0, n): imgClxn = FileImage('/cs/student/kqzhang/cs8/p4images/picture' + str(img) + '.gif') acc.append(imgClxn) i = 0 while True: i = imageChange(i) album(7)
  • 6. #Kevin Zhang and Sijia Sun #Raymond Wong #Section 3 #Project 4 #Creating an Slideshow Window Program from cImage import * myWin = ImageWin("SlideShow", 400, 350) #opens window with dimensions 400x350 bottomBar = FileImage('/cs/student/kqzhang/cs8/p4images/bottom_bar.gif') firstImage = FileImage('/cs/student/kqzhang/cs8/p4images/picture0.gif') firstImage.draw(myWin) bottomBar.setPosition(0,300) bottomBar.draw(myWin) def imageChange(i): change = myWin.getMouse() #print(change) if change[0] in range(20, 60): if change[1] in range(305, 345): #print('left') i = (i-1)%len(acc) acc[i].draw(myWin) elif change[0] in range(340,380): if change[1] in range(305,345): i = (i+1)%len(acc) acc[i].draw(myWin) elif change[0] in range(180, 220): if change[1] in range(305,345): myWin.exitOnClick() return i acc = [] def album(n): #input as 'n' for img in range(0, n): imgClxn = FileImage('/cs/student/kqzhang/cs8/p4images/picture' + str(img) + '.gif') acc.append(imgClxn) i = 0 while True: i = imageChange(i) album(7)