NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

Код для вычисления контрольной суммы с помощью алгоритма "количество 1 в битовом представлении символов исходного текста":

python
def calculate_checksum(text):
checksum = 0
for char in text:
checksum += bin(ord(char)).count('1')
return checksum

text = "Пример текста"
checksum = calculate_checksum(text)
print(checksum)


В этом коде мы определяем функцию calculate_checksum, которая принимает текст в качестве аргумента и вычисляет контрольную сумму, считая количество единиц в битовом представлении каждого символа исходного текста. Мы создаем переменную text, которая содержит пример текста, и затем вызываем функцию calculate_checksum с этим текстом. Результат вычисления контрольной суммы сохраняем в переменную checksum и выводим ее значение на экран.

Код для создания и проверки электронной цифровой подписи с использованием данного алгоритма:

python
import hashlib

def create_signature(text):
checksum = calculate_checksum(text)
return hashlib.md5(str(checksum).encode()).hexdigest()

def verify_signature(text, signature):
checksum = calculate_checksum(text)
expected_signature = hashlib.md5(str(checksum).encode()).hexdigest()
return signature == expected_signature

text = "Пример текста"
signature = create_signature(text)
print(signature)

is_valid = verify_signature(text, signature)
print(is_valid)


В этом коде мы добавляем функцию create_signature, которая вычисляет контрольную сумму текста с помощью функции calculate_checksum и затем создает электронную цифровую подпись, хешируя эту контрольную сумму с использованием алгоритма MD5. Мы также добавляем функцию verify_signature, которая вычисляет контрольную сумму текста и ожидаемую электронную цифровую подпись, а затем проверяет, совпадает ли полученная подпись с ожидаемой. Мы вызываем функцию create_signature для создания подписи и выводим ее значение на экран. Затем мы вызываем функцию verify_signature для проверки подписи и выводим результат проверки на экран.
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.