#๐ Python Cryptography Project Help
30 messages ยท Page 1 of 1 (latest)
@finite summit
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
snippet
Do you have any specific questions?
Questions are more productive than a general "help" request.
!d str.translate - look into str.translate()
str.translate(table)```
Return a copy of the string in which each character has been mapped through the given translation table. The table must be an object that implements indexing via [`__getitem__()`](https://docs.python.org/3/reference/datamodel.html#object.__getitem__), typically a [mapping](https://docs.python.org/3/glossary.html#term-mapping) or [sequence](https://docs.python.org/3/glossary.html#term-sequence). When indexed by a Unicode ordinal (an integer), the table object can do any of the following: return a Unicode ordinal or a string, to map the character to one or more other characters; return `None`, to delete the character from the return string; or raise a [`LookupError`](https://docs.python.org/3/library/exceptions.html#LookupError) exception, to map the character to itself.
You can use [`str.maketrans()`](https://docs.python.org/3/library/stdtypes.html#str.maketrans) to create a translation map from character-to-character mappings in different formats.
See also the [`codecs`](https://docs.python.org/3/library/codecs.html#module-codecs) module for a more flexible approach to custom character mappings.
!d string.ascii_lowercase
string.ascii_lowercase```
The lowercase letters `'abcdefghijklmnopqrstuvwxyz'`. This value is not locale-dependent and will not change.
!d string.ascii_uppercase
string.ascii_uppercase```
The uppercase letters `'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`. This value is not locale-dependent and will not change.
maybe this on in this speciffic assignment
but yeah, but they are kind of the same
i need someone to encrypt
!rule homework
8. Do not help with ongoing exams. When helping with homework, help people learn how to do the assignment without doing it for them.
also no short hand functions
Show the code you have so far
def caesar_encrypt_file(input_filename, output_filename, key):
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
encrypted_lines = []
infile = open(input_filename, 'r')
lines = infile.readlines()
infile.close()
for line in lines:
encrypted_line = ''
for char in line:
if char in alphabet:
index = alphabet.index(char)
new_index = (index + key) % 26
encrypted_line += alphabet[new_index]
else:
encrypted_line += char # Preserve spaces and newlines
encrypted_lines.append(encrypted_line)
outfile = open(output_filename, 'w')
outfile.writelines(encrypted_lines)
outfile.close()
Hey @finite summit!
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
Does it not work?
well i want someone to check yk
and i dont understand what im supposed to submit
and how my file organiation should be
Create an encrypted file with the message "THERE IS A PLOT AGAINST YOU I CAN HELP"
Sounds like you need to input() for the input/output filename and the key
then call your function.
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.