-
-
Notifications
You must be signed in to change notification settings - Fork 49.9k
Vigenere #5868
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
Vigenere #5868
Conversation
Desc: code ask user to leave key blank to generate a random key.
A random key with a length as long as the sent message is
now able to be generated at the users request. The random
key is printed after the encrypted message is printed.
Desc: Funciton documentation written. Documented key print during encryption conditional. Ran black on script.
Desc: the variable translated is now initialized outside the conditional
block where it is first used. Clearing the unbound error.
changed randomKey generator list comprehension code to the basic for loop with enumerate.
Function created that creates a random letter key, based off the length of the message to be encrypted. Added option for user to use the random key function. Added printing of the random key after the printing of the encrypted message.
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
tianyizheng02
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update your fork's main branch and rebase this branch so that this PR is up to date. This file has changed significantly since this PR was made.
| "\nEnter key [alphanumeric], " | ||
| "leave blank for a random key as long as the message." | ||
| ) | ||
| key = str(input("Enter the Key: ").strip()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| key = str(input("Enter the Key: ").strip()) | |
| key = input("Enter the Key: ").strip() |
The str call is unnecessary because input and strip already return strings
| randomKey = False | ||
| if not len(key): | ||
| randomKey = True | ||
| key = generateRandomKey(message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| randomKey = False | |
| if not len(key): | |
| randomKey = True | |
| key = generateRandomKey(message) | |
| randomKey = len(key) == 0 | |
| key = generateRandomKey(message) if randomKey else key |
| print("Message key:\n%s" % key.lower()) | ||
|
|
||
|
|
||
| def generateRandomKey(message: str) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- All functions and variable names follow Python naming conventions.
This means snake case: generate_random_key
| message = message.strip() | ||
| randomKey = [] | ||
|
|
||
| for i, letter in enumerate(message): | ||
| secret_letter = secrets.choice(LETTERS) | ||
| randomKey.append(secret_letter) | ||
|
|
||
| return "".join(randomKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| message = message.strip() | |
| randomKey = [] | |
| for i, letter in enumerate(message): | |
| secret_letter = secrets.choice(LETTERS) | |
| randomKey.append(secret_letter) | |
| return "".join(randomKey) | |
| random_key = [secrets.choice(LETTERS) for _ in message.strip()] | |
| return "".join(random_key) |
|
Closing this PR due to inactivity. Hacktoberfest is drawing near, so we're going to start clearing out inactive PRs from the backlog. |
Describe your change:
Function created that generate a random letter key, based off the length of the message to be encrypted.
Added option for user to use the random key function.
Added printing of the random key after the printing of the encrypted message.
Moved initialization of translated variable outside of conditional block to prevent an
unbound error.
Encryption of a message using this function should not be considered secure.
Still new to git and github. I read the contribute guide and did what I could. Since this generates a random key every time, using doc tests, or unittest may not work. I tested this with many different iterations of: all work and no play make jack a dull boy
in the following manner:
spaces and no spaces
leading, trailing, leading and trailing white space
all lowercase, all uppercase, mixed upper/lower case
algorithm work as far a I can tell.
Ran black, flake8 and pre-commit on the script.
Thanks for opportunity to contribute. Cheers.
Checklist:
Fixes: #{$ISSUE_NO}.