#๐Ÿ”’ Python Cryptography Project Help

30 messages ยท Page 1 of 1 (latest)

finite summit
#

I need help w a python project consisting of encrypting and decrypting a file using ceaser cipher.

I have the text files that I need to derypt/encrypt w python ceaser cipher.

hoary fieldBOT
#

@finite summit

Python help channel opened

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.

finite summit
#

snippet

modest river
#

Do you have any specific questions?

#

Questions are more productive than a general "help" request.

rocky shard
hoary fieldBOT
#

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.
rocky shard
#

!d string.ascii_lowercase

hoary fieldBOT
#

string.ascii_lowercase```
The lowercase letters `'abcdefghijklmnopqrstuvwxyz'`. This value is not locale-dependent and will not change.
fierce oyster
#

!d string.ascii_uppercase

hoary fieldBOT
#

string.ascii_uppercase```
The uppercase letters `'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`. This value is not locale-dependent and will not change.
fierce oyster
#

maybe this on in this speciffic assignment
but yeah, but they are kind of the same

finite summit
modest river
#

!rule homework

hoary fieldBOT
#

8. Do not help with ongoing exams. When helping with homework, help people learn how to do the assignment without doing it for them.

finite summit
warm haven
finite summit
# warm haven 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()
hoary fieldBOT
#

Hey @finite summit!

Please edit your message to use a code block

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
modest river
#

Does it not work?

finite summit
#

well i want someone to check yk

#

and i dont understand what im supposed to submit

#

and how my file organiation should be

modest river
#

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.

finite summit
#

oh ic

#

dude you really are smart man tysm

hoary fieldBOT
#
Python help channel closed for inactivity

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.