#🔒 why my python decode don't working correct

24 messages · Page 1 of 1 (latest)

sacred orbitBOT
#

@pulsar idol

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.

orchid robin
#

@pulsar idol show your code?

pulsar idol
#

yo

pulsar idol
#

65 strings

#

@orchid robin

#

'''the str_split() function splits a string into characters'''
'''функция str_split() разбивает строку на символы'''
def str_split(seq, length):
return [seq[i:i + length] for i in range(0, len(seq), length)]

'''the encode() function encrypts the text with a key that determines the number of columns, and prints the encrypted text by reading the characters across the columns'''
'''функция encode() шифрует текст с ключом, определяющим количество столбцов, и печатает зашифрованный текст, читая символы по столбцам'''
def encode(key, plaintext):
order = {int(val): num for num, val in enumerate(key)}
ciphertext = ''
for index in sorted(order.keys()):
for part in str_split(plaintext, len(key)):
try:ciphertext += part[order[index]]
except IndexError:
continue
return ciphertext

#

'''Please implement the decode() function'''
'''Функцию decode() реализуйте сами'''
def decode(key, ciphertext):
# Determine the order of columns based on the key
order = {int(val): num for num, val in enumerate(key)}

# Determine the number of columns
num_columns = len(key)

# Initialize a list of columns to store characters
columns = [''] * num_columns

# Iterate over the ciphertext, filling the columns
col_index = 1  # Start from 1 instead of 0
for char in ciphertext:
    columns[order[col_index]] += char
    col_index = (col_index % num_columns) + 1  # Adjust index to start from 1

# Concatenate characters from each column to obtain plaintext
plaintext = ''.join(columns)

return plaintext.rstrip('$')  # Remove any trailing '$' characters

'''Setting the key/Задаем ключ key:'''
key = '3421'

'''Setting the plaintext/Задаем открытый текст'''
Text = 'Hello, world'

'''Let's add a non-significant text to the last row in the table (add the "$" sign)'''
'''Дополним незначащим текстом последнюю строку в таблице (допишем знак "$")'''
AddTextNum = len(Text) % len(key)
for k in range(AddTextNum):
Text = Text + '$'
#print ("Plaintext: \n", Text, "\n")

'''We encrypt the plaintext supplemented with special, insignificant, text'''
'''Шифруем открытый текст, дополненный незначащим текстом'''
Encrypted = encode(key, Text)
print("\nCiphertext: \n", Encrypted, "\n")

'''We decrypt the ciphertext'''
'''Расшифруем криптограмму'''
Decrypted = decode('2413', Encrypted)

print("Plaintext: \n", Decrypted, "\n")
print("Plaintext in a table form: \n")

#

@heavy plume this is a task Complications of the simple vertical permutation cipher (SVPS)
For the definition of PVPS (without complications), see, for example, paragraph 1.3. books
B. Schneier “Applied cryptography”
a) In the file XTransposition_Cipher_Complicated.py,
PVPS encryption with alternative keys is implemented, then
there is a key in such a cipher 𝑘 has the form 𝑘 = 𝑎1𝑎2 … 𝑎𝑚, where
𝑎1, 𝑎2, … , 𝑎𝑚 are different numbers from 1 to m, and m is the number
columns (key) in the table. Note that in the usual PVPS 𝑘 =
12…𝑚.
Add this script by implementing
✓ the Decode() function, which performs decryption,
✓ output of plaintext in a line and in the form of a table.
Please submit the source code as an answer.
b) Given is the C1 ciphergram obtained by PVPS.
✓ After performing cryptanalysis, find the plaintext T1 and the key
K1 encryption.
✓ Encrypt the plaintext T2 using the found key,
having received the C2 ciphergram.
Provide C2 as an answer.
C1:
Osfshnsaқmyrsrtryөsdovөyayyіқzіynozndnrnmgzbylaa
YAUDUDEIIKRALETRARARAAYAIIIIROA
T2:
ZHZHELZHYNEASDATKLRIENA-SYSPYSRIKUATYIZADUEGLTYAYR
ADDURYSZELIҢAE

#

@orchid robin are you here?

orchid robin
#

!paste

sacred orbitBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

pulsar idol
orchid robin
#

You didn't write a decode function

pulsar idol
#

@orchid robin it's a wrong code?

#

or this need to work like that?

orchid robin
#

What does it do when you run it?

pulsar idol
#

only decode

orchid robin
#

What does it do when you run it?

sacred orbitBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.

#

🔒 why my python decode don't working correct