Skip to content

Created Encrypt_Decrypt program #489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

AmulyaJain2004
Copy link

@AmulyaJain2004 AmulyaJain2004 commented May 15, 2024

This Program allows user to encrypt or decrypt messages. Could you review the program and merge the pull request?

Program that allows you to encrypt and decrypt messages (strings) by shifting the ascii values to make new string (encrypt or decrypt message).
Program alows user to encrypt or decrypt the message (strings).
Copy link

@Ruhan-Saad-Dave Ruhan-Saad-Dave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice, but do you know you can use list comprehension to shorten the code? I have made an example, also the fancy way in which I have defined the function is called type hinting incase if you don't know:

def main():
'''
The main function to be executed in the program.
'''

choice = input("Type 'encode' to encrypt, Type 'decode' to decrypt\n").lower()
text = input("Type your message (only text message without spaces): \n").lower()
shift = int(input("Type your shift number: \n"))
if choice == "encode":
text_change(text, shift, 1)
elif choice == "decode":
text_change(text, shift, -1)
else :
print("You should have entered correct choice!!")
return 0
alphabet = ["a","b","c","d","e","f","g","h","k","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

def text_change(string: str, shift: int, mode: int) -> None:
'''
Takes in the string and shift and convert it based on the mode.

parameters:

  • string (str type): The text to encode or decode
  • shift (int type): The shift to apply on the message, its like a special key
  • mode (int type): 1 for encode, -1 for decode
  • returns nothing (None)
    '''
    print([chr(ord(i) + mode shift) for i in list(string)], sep = "", end = "")
    if name == "main":
    main()

@AmulyaJain2004
Copy link
Author

Yes, definitely it can also be implemented which will reduce code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants