Какова вероятность столкновения CRC32 всех возможных строк ASCII переменной длины от 1 до 7?Python

Программы на Python
Anonymous
Какова вероятность столкновения CRC32 всех возможных строк ASCII переменной длины от 1 до 7?

Сообщение Anonymous »


I am trying to find the CRC32 collision probability among all possible ASCII strings of variable length ranging from 1 to 7. Here an ASCII character can range from ASCII 32 to ASCII 126. I tried to run my program in my PC, but due to high requirement of CPU, the program would crash and never run to completion. Is there any other way to find this out.

my code is as below:
import binascii from itertools import product def crc32_all_ascii_strings(length): strings = [] for chars in product(range(32, 127), repeat=length): strings.append(''.join(chr(c) for c in chars)) crc32_dict = {} for string in strings: crc32 = binascii.crc32(string.encode()) & 0xFFFFFFFF if crc32 not in crc32_dict: crc32_dict[crc32] = [] crc32_dict[crc32].append(string) return crc32_dict if __name__ == "__main__": for length in range(1, 8): crc32_dict = crc32_all_ascii_strings(length) for crc32, string_list in crc32_dict.items(): if len(string_list) > 1: print(f"CRC32: {crc32:08X}") for string in string_list: print(f" {string}")

Источник: https://stackoverflow.com/questions/780 ... of-variabl

Вернуться в «Python»