Python Forum
How can I use CRC libs in python?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I use CRC libs in python?
#1
Hi! I'm trying to use the checksum algorithm CRC in my code (python), but I'm facing several dificulties. I tried to implement a CRC algorithm by my own but it's completely bad, a file of 20MB cost me 10+ minutes to calculate the CRC, add to the bitvector and resolve the bitvector.

After that I tried to use some librarys but i dont know how to use them at all. Searching in the web I founded some examples that helped me to calculate the CRC, but i dont know how to add it in the bitvector and resolve.

Can someone help me? I just need some examples of how to use one library or an algorithm that really work to implement.

I tried to use the the crc8, crccheck, crcmod and pycrc libraries.

I'm trying to open a file -> transform into bytes -> calculate the CRC -> send -> recieve -> verify the CRC -> open the file.

My actual code:

import base64
import sys
from os import startfile

def codifica():    
    print("Digite o Nome.extensão ou Diretorio do arquivo:")
    arquivo = input()
    data_input = open(arquivo, "rb")
    data = base64.b64encode(data_input.read())
    data_input.close()

    check = arquivo[0] + arquivo[1] + arquivo[2]
    if(check == 'C:\\'):
        D = arquivo.split('\\')
        auxname = D[len(D) - 1]
        Nome = auxname.split('.')
    else:
         Nome = arquivo.split('.')
    saida = Nome[0] +'LI-FI.' + Nome[1]
    print(saida)
    return data

def decodifica(data):
    new_output = base64.b64decode(data)
    new_data = open('saida.png','wb')
    new_data.write(new_output)
    new_data.close()
    startfile('saida.png')

def crc (dados_str):
    poly_str = '1111110'
    n = len(dados_str)-2
    crc_n = len(poly_str)-1
    dados = int(dados_str,2)
    dados = dados << crc_n
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Running 3rd party libs on Steam Deck (Arch Linux) with restricted access metulburr 0 1,875 Jan-07-2023, 10:41 PM
Last Post: metulburr
  Mad Libs Program theguywithcurls 10 5,078 Nov-17-2019, 12:36 AM
Last Post: theguywithcurls
  using py32, just need py64 LIBS for now, how to install? davecotter 1 2,295 Jan-29-2019, 10:40 PM
Last Post: davecotter
  [split] adding 3rd party libs Blue Dog 7 6,850 Oct-22-2016, 12:03 PM
Last Post: Blue Dog

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020