Answers for "encoding and decoding in python"

2

encoding and decoding in python

alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

def caesar(start_text, shift_amount, cipher_direction):
  end_text = ""
  if cipher_direction == "decode":
    shift_amount *= -1
  for char in start_text:
    if char in alphabet:
      position = alphabet.index(char)
      new_position = position + shift_amount
      end_text += alphabet[new_position]
    else:
      end_text += char
  print(f"Here's the {cipher_direction}d result: {end_text}")


should_end = False
while not should_end:

  direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n")
  text = input("Type your message:\n").lower()
  shift = int(input("Type the shift number:\n"))
  shift = shift % 26

  caesar(start_text=text, shift_amount=shift, cipher_direction=direction)

  restart = input("Type 'yes' if you want to go again. Otherwise type 'no'.\n")
  if restart == "no":
    should_end = True
    print("Thanks for using me")
Posted by: Guest on June-30-2021
0

decoding encoding script for pythong

#novince coder, dont know if im doing this right XD
EncodingValues = ['q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m','Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B',',','N','M','!','@','$','%','^','&','*','(',')','_','+','-','=','#']
encode = "this"

def encode(string):
  encodedcode = ""
  LetterToEncode = 0
  for i in string:
    LetterToEncode = LetterToEncode + 1
    encodedcode = encodedcode + EncodingValues.index(LetterToEncode)
    encodedcode = encodedcode + " "
    #still editing this
  
def decode(string):
  decodedcode = ""
  LetterToDecode = 0
  for i in string:
    LetterToDecode = LetterTodecode + 1
    if string.index(letterToDecode + 2) = " "
    decodedcode = decodedcode + EncodingValues.index(LetterToDecode)
Posted by: Guest on October-21-2020

Python Answers by Framework

Browse Popular Code Answers by Language