Skip to content

Conversation

@itsf4llofstars
Copy link

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.

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

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.
@ghost ghost added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Dec 8, 2021
@stale
Copy link

stale bot commented Apr 19, 2022

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.

@stale stale bot added the stale Used to mark an issue or pull request stale. label Apr 19, 2022
Copy link
Contributor

@tianyizheng02 tianyizheng02 left a 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())
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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

Comment on lines +15 to +18
randomKey = False
if not len(key):
randomKey = True
key = generateRandomKey(message)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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:
Copy link
Contributor

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

Comment on lines +53 to +60
message = message.strip()
randomKey = []

for i, letter in enumerate(message):
secret_letter = secrets.choice(LETTERS)
randomKey.append(secret_letter)

return "".join(randomKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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)

@stale stale bot removed the stale Used to mark an issue or pull request stale. label Jul 31, 2023
@tianyizheng02
Copy link
Contributor

Closing this PR due to inactivity. Hacktoberfest is drawing near, so we're going to start clearing out inactive PRs from the backlog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants