Activity

  • MTGreen posted an update in the group Group logo of Python For HackersPython For Hackers 1 year, 5 months ago

    I used python to encrypt a message.

    GPKYFE TRE VETIPGK FI UVTIPGK

    Around Sunday night I will post the massage and the code to both encrypt or decrypt.

    Can you tell me the deciphered message?

    Can you give us some python code to show how to get to the message?

    • Key : 17
      Time Taken in Seconds : 0.0110001564026
      PYTHON CAN ENCRYPT OR DECRYPT

    • Okay,
      I have issues with proper tabbing, but I will post the code and you will have to adjust the tabs.

      # Program to Encrypt and Decrypt using CAESAR Shift Ciphers
      import os
      import string
      import time
      def Encrypt():
      print ”’
      ################################
      Enter the Value of the Key #
      #
      #
      ################################
      ”’
      KEY = raw_input()
      print ”’
      #########################################
      Enter the plain text that is required to#
      be encrypted #
      #
      #########################################
      ”’
      plain = raw_input()
      #### Assigning Numbers to Alphabets #####
      ct, al = [], [] # ct is count and al is alphabet
      for x in range(0, 26):
      ct.append(x)
      for x in string.ascii_uppercase:
      al.append(x)
      scmap = dict(zip(ct, al))
      print”’
      #########################################
      #The dict of alphabet mapping to numbers#
      #########################################
      ”’
      print scmap
      ### generating Cipher Text
      cipher = “”
      for x in plain.upper():
      if x.isalpha():
      new = int(KEY) + int(list(scmap.keys())[list(scmap.values()).index(x)])
      if new >25:
      new1 = new%26
      cipher+=scmap[new1]
      else:
      cipher+=scmap[new]
      else:
      cipher+=str(x)
      print ”’
      ##################################
      #Cipher Text of the Plain Text is#
      ##################################
      ”’
      print cipher
      def Decrypt():
      print ”’
      #########################################
      Enter the cipher text that is required #
      to be decrypted #
      #
      #########################################
      ”’
      cipher = raw_input()
      #### Assigning Numbers to Alphabets #####
      ct, al = [], [] # ct is count and al is alphabet
      for x in range(0, 26):
      ct.append(x)
      for x in string.ascii_uppercase:
      al.append(x)
      scmap = dict(zip(ct, al))
      print”’
      #########################################
      #The dict of alphabet mapping to numbers#
      #########################################
      ”’
      print scmap
      ### Decrypting the Cipher Text
      for key in range(0,26):
      Start = time.time()
      plain = “”
      for x in cipher.upper():
      if x.isalpha():
      new = int(list(scmap.keys())[list(scmap.values()).index(x)]) – int(key)
      if new < 0:
      new1 = new % 26
      plain += scmap[new1]
      else:
      plain += scmap[new]
      else:
      plain += str(x)
      print '''
      ###########################################
      # Key and Plain Text of the Cipher Text is#
      ###########################################
      '''
      print "Key :", key
      print "Time Taken in Seconds :", float(time.time() – Start)
      print plain
      def main():
      print '''
      Are you Encrypting or Decrypting using Brute Force
      Enter E for Encryption or D for Decryption
      '''
      choice = raw_input()
      print choice.upper()
      if choice.upper() == "E":
      Encrypt()
      elif choice.upper() == "D":
      Decrypt()
      elif choice.upper()!= 'E' or choice.upper() != 'D':
      print "Invalid Choice. Make Your Choice Correctly and Rerun the program"
      main()

    • I created a GitHub account and posted the code here if you want to try it, tabs and all. https://github.com/MTGreen/Lab/blob/master/CaeserEnDec.py

Copyright ©2020 Caendra, Inc.

Contact Us

Thoughts, suggestions, issues? Send us an email, and we'll get back to you.

Sending

Sign in with Caendra

Forgot password?Sign up

Forgot your details?