Exemple #1
0
    def post(self):  #gathers user input and passes it to write_content
        rotate_recieved = self.request.get("rot")
        if rotate_recieved == 3.14 or str(rotate_recieved) == "pi":
            pass
        try:
            rotate_recieved = int(rotate_recieved)
            message_recieved = self.request.get("message")
            encrypted_message = caesar.encrypt(message_recieved,
                                               int(rotate_recieved))
            safe_message = cgi.escape(encrypted_message)

            form = "<form method='post'>" + write_content(
                rotate_recieved, safe_message) + "</form>"
            self.response.write(form)
        except:
            rotate_recieved = 0
            message_recieved = self.request.get("message")
            encrypted_message = caesar.encrypt(message_recieved,
                                               int(rotate_recieved))
            safe_message = cgi.escape(encrypted_message)

            form = "<form method='post'>" + write_content(
                rotate_recieved, safe_message
            ) + "</form>" + "<p style='color:red;'>" + "Rotation amount must be an integer!" + "</p>"
            self.response.write(form)
Exemple #2
0
def test_encrpyt():
    #regl'r cipher
    k = 3
    m = "Hello"
    assert encrypt(k, m) == "khoor"
    
    #What if k is big?
    k = 14
    m = "Hello"
    assert encrypt(k,m) == "vszzc"
    
    #handles spaces by leaving spaces alone.
    k=3
    m = "Hello hello"
    assert encrypt(k,m) == "khoor khoor"
Exemple #3
0
def vigenere(text,encryption_key):
    encrypt_code_list = []
    encrypt_text = ""
    for char in encryption_key:
        encrypt_code_list.append(alphabet_position(char))
    i = 0
    for char in text :
        if char == encrypt(char, encrypt_code_list[i]):
            encrypt_text = encrypt_text + char
        else: 
            encrypt_text = encrypt_text + encrypt(char, encrypt_code_list[i])
            i = i + 1
        if i == (len(encrypt_code_list)):
            i = 0
    return(encrypt_text)
Exemple #4
0
def encryption():
    if request.method == 'POST':
        shift = request.form['shift']
        plaintext = request.form['plaintext']
        shift = int(shift)
        new_message = encrypt(plaintext, shift)
        return render_template('index.html', new_message=new_message)
Exemple #5
0
 def post(self):
     rotation = int(self.request.get("Rotation"))
     text = self.request.get("text")
     encrypted_msg = caesar.encrypt(text, rotation)
     escaped_msg = cgi.escape(encrypted_msg)
     content = build_page(escaped_msg)
     self.response.write(content)
Exemple #6
0
def test_caesar_encrypt_upper():
    """
    Test caesar upper
    """
    assert caesar.encrypt(
        "the quick brown fox jumps over the lazy dog".upper(),
        10) == "DRO AESMU LBYGX PYH TEWZC YFOB DRO VKJI NYQ"
Exemple #7
0
 def post(self):
     message = self.request.get("message")
     rotation = int(self.request.get("rotation"))
     encrypted_message = caesar.encrypt(message, rotation)
     escaped_message = cgi.escape(encrypted_message)
     content = build_page(escaped_message)
     self.response.write(content)
Exemple #8
0
 def post(self):
     message = self.request.get("message")
     rot = self.request.get("rot")
     encrypted_text = caesar.encrypt(message, rot)
     escaped_message = cgi.escape(encrypted_text)
     content = build_page(escaped_message)
     self.response.write(content)
Exemple #9
0
 def post(self):
     message = self.request.get("message") #hello</textarea>hello
     rotation = int(self.request.get("rotation")) # 0
     encrypted_message = caesar.encrypt(message, rotation) #hello</textarea>hello
     escaped_message = cgi.escape(encrypted_message) # hello&lt;/textarea&gt;hello
     content = build_page(escaped_message)
     self.response.write(content)
Exemple #10
0
    def post(self):
        text = self.request.get("text")
        num = int(self.request.get("num"))

        answer = encrypt(text, num)

        self.response.out.write(page_header.format(answer))
Exemple #11
0
def Caesar():
  msg = ''
  output = ''
  set1 = 'opt1'
  set2 = 'opt4'
  shift = '0'
  if request.method == 'POST':
    task = request.form.get('task')
    msg = request.form.get('original-text')
    set1 = request.form.get('set1')
    set2 = request.form.get('set2')
    shift = request.form.get('shift')
    if task == 'encrypt':
      output = caesar.encrypt(msg,int(shift))
      if set1 == 'opt1':
        pass
      elif set1 == 'opt2':
        output = removeAllSpecialCharactersExcludingSpaces(output)
      elif set1 == 'opt3':
        output = removeAllSpecialCharactersIncludingSpaces(output)
    elif task == 'decrypt':
      output = caesar.decrypt(msg,int(shift))
      if set1 == 'opt1':
        pass
      elif set1 == 'opt2' :
        output = removeAllSpecialCharactersExcludingSpaces(output)
      elif set1 == 'opt3':
        output = removeAllSpecialCharactersIncludingSpaces(output)
    if set2 == 'opt4':
        pass
    elif set2 == 'opt5':
      output = output.upper()
    elif set2 == 'opt6':
      output = output.lower()
  return render_template('caesar.html', title='Caesar Cipher', msg=msg, output=output, set1=set1, set2=set2, shift=shift)
Exemple #12
0
 def post(self):
     message = self.request.get("message")
     rotation = int(self.request.get('rotation'))
     encrypted_message = caesar.encrypt(message, rotation) # hello</textarea>hello
     escaped_message = cgi.escape(encrypted_message)
     content = build_page(escaped_message)
     self.response.write(content)
Exemple #13
0
    def post(self):
        message = self.request.get("message")
        rot = self.request.get("rot")

        encrypted_message = caesar.encrypt(message, int(rot))
        escaped_message = cgi.escape(encrypted_message)
        self.response.write(build_page(escaped_message, int(rot)))
Exemple #14
0
 def post(self):
     message = self.request.get("message")
     rot = int(self.request.get('rotation'))
     encryptedMessage = caesar.encrypt(message, rot)
     escapedMessage = cgi.escape(encryptedMessage)
     content = buildPage(escapedMessage)
     self.response.write(content)
Exemple #15
0
 def post(self):
     text = self.request.get('text')
     rot = self.request.get('rot')
     rot = int(rot)
     rot13 = encrypt(text, rot)
     response = (form % {"text": rot13})
     self.response.write(response)
Exemple #16
0
def test_caesar_encrypt_zapor():
    """
    Test caesar zapor
    """
    assert caesar.encrypt(
        "the quick Brown fox_ jumps over the laZy dog?",
        -500) == "nby kocwe Vliqh zir_ dogjm ipyl nby fuTs xia?"
Exemple #17
0
 def post(self):
     rot = self.request.get("rot")
     text = self.request.get("text")
     rot = int(rot)
     answer = encrypt(text, rot)
     answer_escaped = cgi.escape(answer)
     self.response.out.write(form % {"error": answer_escaped})
Exemple #18
0
def encrypto():
    rot = request.form['rot']
    rot = int(rot)
    text = request.form['text']
    new = encrypt(text, rot)

    return form.format(new)
Exemple #19
0
def test_caesar_encrypt_insane():
    """
    Test caesar insane
    """
    assert caesar.encrypt(
        "the quick brown fox jumps over the lazy dog?",
        500) == "znk waoiq hxuct lud pasvy ubkx znk rgfe jum?"
Exemple #20
0
def webEncrypt():

    toEncrypt = request.form['text']
    numRot = int(request.form['rot'])
    newMessage = encrypt(toEncrypt, numRot)

    return form.format(newMessage)
Exemple #21
0
 def post(self, crip=""):
 	answer = self.request.get('crip')
 	number = self.request.get("number")
 	newstr = caesar.encrypt(answer,int(number))
 	escaped_message = cgi.escape(newstr)
 	form2 = """<form method= "post"><h1>Enter some text to ROT13:</h1><p>Your coded message rotated by """+ number + """!</p><textarea name="crip">""" + escaped_message +"""</textarea><br><br><input type="submit"></form>"""
 	self.response.write(form2)
Exemple #22
0
 def post(self):
 	message = self.request.get("message")
 	rotate = int(self.request.get("rotate"))
 	enc_message = caesar.encrypt(message, rotate)
 	esc_message = cgi.escape(enc_message)
 	content = landing_page(esc_message)
 	self.response.write(content)
Exemple #23
0
def test(input, password):
    cprint("Input:", attrs=["bold", "underline"])
    print(input + "\n")

    cprint("Password:"******"bold", "underline"])
    print(password + "\n")

    output = caesar.encrypt(input, password)
    cprint("Output:", attrs=["bold", "underline"])
    print(output + "\n")

    revInput = caesar.decrypt(output, password)
    cprint("Reversed input:", attrs=["bold", "underline"])
    print(revInput)

    if revInput == input:
        cprint("(Correct)\n", "green")

    else:
        cprint("\nIncorrect en-/decryption!", "red")
        sys.exit(1)

    revPassword = reconstruct.reconstruct(input, output)
    cprint("Reversed password:"******"bold", "underline"])
    print(revPassword)

    if reconstruct.compare(reconstruct.convertPassword(password), revPassword):
        cprint("(Correct)", "green")

    else:
        cprint("\nIncorrect reconstruction!", "red")
        sys.exit(1)
Exemple #24
0
 def post(self):
     userNumber = self.request.get('rot')
     userNumber = int(userNumber)
     userText = self.request.get('text')
     userText = encrypt(userText, userNumber)
     userText = cgi.escape(userText, quote=True)
     self.write_form(userText)
Exemple #25
0
 def post(self):
     rot = self.request.get("rot")
     rot = int(rot)
     text = self.request.get("text")
     text = cgi.escape(text, quote = True)
     user_encrypt = encrypt(text, rot)
     self.response.write(form_data % {"value": user_encrypt})
Exemple #26
0
    def post(self):
        message = self.request.get("message")
        rot = self.request.get("rot")
        coded = caesar.encrypt(message, int(rot))
        escaped_message = cgi.escape(coded)

        content = build_page(escaped_message, rot)
        self.response.write(content)
Exemple #27
0
 def post(self):
     message = self.request.get("userTextArea")
     rotVal = self.request.get("userInpRotation")
     rotVal = int(rotVal)
     encrypted_message = caesar.encrypt(message, rotVal)
     escape_message = cgi.escape(encrypted_message)
     content = page_build(escape_message)
     self.response.write(content)
Exemple #28
0
    def post(self):
        message = self.request.get("message_textarea")
        num = int(self.request.get("rotation_number"))
        encrypted_message = caesar.encrypt(message, num)
        escaped_message = cgi.escape(encrypted_message)

        content = build_page(escaped_message)
        self.response.write(content)
Exemple #29
0
 def post(self):
     old_string = self.request.get("old_string")
     old_string = cgi.escape (old_string)
     rot = self.request.get("rot")
     rotint = int(rot)
     new_string = encrypt(old_string,rotint)
     self.response.out.write("<p>" + old_string + " is the unencrypted version of your word!"+"</p>")
     self.response.out.write("<p>"+new_string + " is the encrypted version of your word!"+"</p>")
Exemple #30
0
    def post(self):
        message = self.request.get("message") #whatever they type
        rotation = int(self.request.get("rotation"))
        encrypted_message = caesar.encrypt(message,rotation) #messge with brackets
        escaped_message = cgi.escape(encrypted_message)
        content = build_page(escaped_message)

        self.response.write(content)
Exemple #31
0
	def get(self):
		message = 'Hello World'
		encrypted_message = caesar.encrypt(message, 13)

		textarea = "<textarea>" + encrypted_message + "</textarea>"
		submit = "<input type='submit'/>"
		form = "<form>" + textarea + "<br>" + submit + "</form>"
		self.response.write(form)
Exemple #32
0
def encrypt(cypher, msg, key):
    crypt = ''
    if cypher == "caesar":
        crypt = caesar.encrypt(msg, int(key))
    elif cypher == "vigenere":
        crypt = vigenere.encrypt(msg, key)
    else:
        print 'cypher not found'
        return 0
    return crypt
Exemple #33
0
def main():
    """Plot relative frequency graph for Caesar, Vigenere, Hill & Playfair ciphers"""
    #Values
    inputfile = sys.argv[1]
    caesar_key = 3
    vigenere_key = 'Vigenere'
    hill_key = hill.npmatrix([[6,24,1],[13,16,10],[20,17,15]])
    playfair_key = 'Playfair key'

    #Plaintext
    plaintext = open(inputfile, 'r').read().upper()
    freq_plain = Counter(plaintext)
    e_count = freq_plain['E']
    freq_plain = sorted([freq_plain[c] for c in letters], reverse=True)
    freq_plain = [i/float(e_count) for i in freq_plain]

    #Caesar
    caesar_text = caesar.encrypt(plaintext, caesar_key)
    freq_caesar = Counter(caesar_text)
    freq_caesar = sorted([freq_caesar[c] for c in letters], reverse=True)
    freq_caesar = [i/float(e_count) for i in freq_caesar]
    
    #Vigenere
    vigenere_text = vigenere.encrypt(plaintext, vigenere_key)
    freq_vigenere = Counter(vigenere_text)
    freq_vigenere = sorted([freq_vigenere[c] for c in letters], reverse=True)
    freq_vigenere = [i/float(e_count) for i in freq_vigenere]

    #Hill
    hill_text = hill.encrypt(plaintext, hill_key)
    freq_hill = Counter(hill_text)
    freq_hill = sorted([freq_hill[c] for c in letters], reverse=True)
    freq_hill = [i/float(e_count) for i in freq_hill]

    #Playfair
    playfair_text = playfair.encrypt(plaintext, playfair_key)
    freq_playfair = Counter(playfair_text)
    freq_playfair = sorted([freq_playfair[c] for c in letters], reverse=True)
    freq_playfair = [i/float(e_count) for i in freq_playfair]

    #Plotting linegraphs
    line_chart = pygal.Line(config=CustomConfig2, style=RedBlueStyle, y_title='Relative frequency')
    line_chart.title = 'Relative frequency for various ciphers'
    line_chart.add('Plaintext', freq_plain)
    line_chart.add('Caesar', freq_caesar)
    line_chart.add('Vigenere', freq_vigenere)
    line_chart.add('Hill', freq_hill)
    line_chart.add('Playfair', freq_playfair)
    line_chart.render_in_browser()
    print Counter(plaintext)
Exemple #34
0
import caesar
if __name__ == '__main__':
    en = [('MIRACLE', 3), ('CALCULATOR', 11), ('ELECTRONIC MAIL', 5), 
          ('DIGITAL SIGNATURE', 2)]
    de = ['IGQTI GYCUJ KPIVQ PXXXX', 'UIPNB TKFGG FSTPO', 
          'AREYY KYYOS VYUTM XGTZ', 'CDTC JCON KPEQ NP', 'ECFDEPO ALCEJ']
    for pt in en:
        print caesar.encrypt(pt[0], pt[1])
    for pt in de:
        print "----------------------------------------"
        print pt
        for (k, s) in enumerate(caesar.try_decrypt(pt)):
            print "%s k=%d" % (s, k)
        print "----------------------------------------"