How to use crc method in fMBT

Best Python code snippet using fMBT_python

crcPoly.py

Source:crcPoly.py Github

copy

Full Screen

1# http://reveng.sourceforge.net/crc-catalogue/all.htm2"""3Library of common CRC configurations4:note: POLY is the polynome of CRC and specifies which bits5 should be xored together.6:note: WIDTH - specifies the width of CRC state/value7:note: REFIN - If it is True the bits in each byte are reversed before processing.8:note: REFOUT If it is set to FALSE, the9 final value in the register is fed into the XOROUT stage directly,10 otherwise, if this parameter is TRUE, the final register value is11 reflected first.12:note: XOROUT This is an WIDTH-bit value. It is XORed to the final register value13 (after the REFOUT) stage before the value is returned as the official14 checksum.15:note: http://reveng.sourceforge.net/crc-catalogue/all.htm16:note: https://github.com/nanpuyue/crc/blob/master/CRC.txt17"""18class CRC_POLY:19 """20 Base class for crc configuration specifications21 """22 POLY = None23 WIDTH = None24 INIT = 025 REFIN = False26 REFOUT = False27 XOROUT = 028class CRC_1(CRC_POLY):29 """30 also known as parity bit31 """32 POLY = 0x133 WIDTH = 134class CRC_3_GSM(CRC_POLY):35 """36 Used in mobile networks37 """38 INIT = 0x039 POLY = 0x340 XOROUT = 0x0741 WIDTH = 342class CRC3_ROHC(CRC_POLY):43 "CRC-3/ROHC (Robust header compression rfc3095)"44 WIDTH = 345 POLY = 0x0346 INIT = 0x0747 REFIN = True48 REFOUT = True49 CHECK = 0x650 RESIDUE = 0x051class CRC_4_ITU(CRC_POLY):52 """53 G.70454 """55 POLY = 0x356 WIDTH = 457 REFIN = True58 REFOUT = True59 CHECK = 0x760 RESIDUE = 0x061class CRC_5_EPC(CRC_POLY):62 """63 Gen 2 RFID EPC-C1G264 """65 POLY = 0x0966 WIDTH = 567 CHECK = 0x0068 RESIDUE = 0x0069class CRC_5_ITU(CRC_POLY):70 """71 G.70472 """73 POLY = 0x1574 WIDTH = 575class CRC_5_USB(CRC_POLY):76 """77 USB token packets78 """79 CHECK = 0x1980 INIT = 0b1111181 REFIN = True82 REFOUT = True83 RESIDUE = 0b0110084 POLY = 0x0585 WIDTH = 586 XOROUT = 0x1f87class CRC_6_CDMA2000_A(CRC_POLY):88 "Used in mobile networks"89 POLY = 0x2790 WIDTH = 691class CRC_6_CDMA2000_B(CRC_POLY):92 "Used in mobile networks"93 POLY = 0x0794 WIDTH = 695class CRC_6_DARC(CRC_POLY):96 "Data Radio Channel"97 POLY = 0x1998 WIDTH = 699class CRC_6_GSM(CRC_POLY):100 "Used in mobile networks"101 POLY = 0x2F102 WIDTH = 6103class CRC_6_ITU(CRC_POLY):104 "Used in G.704"105 POLY = 0x03106 WIDTH = 6107class CRC_7(CRC_POLY):108 "Used in telecom systems, G.707,G.832, MMC, SD"109 POLY = 0x09110 WIDTH = 7111class CRC_7_MVB(CRC_POLY):112 "Used in Train Communication Network, IEC 60870-5"113 POLY = 0x65114 WIDTH = 7115class CRC_8(CRC_POLY):116 "Used in DVB-S2"117 POLY = 0xD5118 WIDTH = 8119class CRC_8_AUTOSAR(CRC_POLY):120 "Used in automotive integration, OpenSafety"121 POLY = 0x2F122 WIDTH = 8123class CRC_8_Bluetooth(CRC_POLY):124 "Used in wireless connectivity"125 POLY = 0xA7126 WIDTH = 8127class CRC_8_CCITT(CRC_POLY):128 "Used in I.432.1; ATM HEC, ISDN HEC and cell delineation"129 CHECK = 0xf4130 POLY = 0x07131 WIDTH = 8132 RESIDUE = 0x00133class CRC_8_Dallas_Maxim(CRC_POLY):134 "Used in 1-Wire bus"135 POLY = 0x31136 WIDTH = 8137class CRC_8_DARC(CRC_POLY):138 "Used in Data Radio Channel"139 POLY = 0x39140 WIDTH = 8141class CRC_8_GSM_B(CRC_POLY):142 "Used in mobile networks"143 POLY = 0x49144 WIDTH = 8145class CRC_8_SAE_J1850(CRC_POLY):146 "Used in AES3"147 POLY = 0x1D148 WIDTH = 8149class CRC_8_WCDMA(CRC_POLY):150 "Used in mobile networks"151 CHECK = 0x25152 INIT = 0X00153 POLY = 0x9B154 REFIN = True155 REFOUT = True156 RESIDUE = 0x00157 WIDTH = 8158class CRC_10(CRC_POLY):159 "Used in ATM; I.610"160 POLY = 0x233161 WIDTH = 10162class CRC_10_CDMA2000(CRC_POLY):163 "Used in mobile networks"164 POLY = 0x3D9165 WIDTH = 10166class CRC_10_GSM(CRC_POLY):167 "Used in mobile networks"168 POLY = 0x175169 WIDTH = 10170class CRC_11(CRC_POLY):171 "Used in FlexRay"172 POLY = 0x385173 WIDTH = 11174class CRC_12(CRC_POLY):175 "Used in telecom systems"176 POLY = 0x80F177 WIDTH = 12178class CRC_12_CDMA2000(CRC_POLY):179 "Used in mobile networks"180 POLY = 0xF13181 WIDTH = 12182class CRC_12_GSM(CRC_POLY):183 "Used in mobile networks"184 POLY = 0xD31185 WIDTH = 12186class CRC_13_BBC(CRC_POLY):187 "Used in Time signal, Radio teleswitch"188 POLY = 0x1CF5189 WIDTH = 13190class CRC_14_DARC(CRC_POLY):191 "Used in Data Radio Channel[19]"192 POLY = 0x0805193 WIDTH = 14194class CRC_14_GSM(CRC_POLY):195 "Used in mobile networks"196 POLY = 0x202D197 WIDTH = 14198class CRC_15_CAN(CRC_POLY):199 POLY = 0x4599200 WIDTH = 15201class CRC_15_MPT1327(CRC_POLY):202 POLY = 0x6815203 WIDTH = 15204class CRC_16_Chakravarty(CRC_POLY):205 "Used in Optimal for payloads ≤64 bits"206 POLY = 0x2F15207 WIDTH = 16208class CRC_16_ARINC(CRC_POLY):209 "Used in ACARS applications"210 POLY = 0xA02B211 WIDTH = 16212class CRC_16_CCITT(CRC_POLY):213 """214 Used in X.25, V.41, HDLC FCS, XMODEM, Bluetooth, PACTOR, SD, DigRF, many others;215 Also known as CRC_CCITT216 """217 INIT = 0xFFFF218 POLY = 0x1021219 WIDTH = 16220class CRC_16_CDMA2000(CRC_POLY):221 "Used in mobile networks"222 POLY = 0xC867223 WIDTH = 16224class CRC_16_DECT(CRC_POLY):225 "Used in cordless telephones"226 POLY = 0x0589227 WIDTH = 16228class CRC_16_T10_DIF(CRC_POLY):229 "Used in SCSI DIF"230 POLY = 0x8BB7231 WIDTH = 16232class CRC_16_DNP(CRC_POLY):233 "Used in DNP, IEC 870, M-Bus"234 POLY = 0x3D65235 WIDTH = 16236class CRC_16_IBM(CRC_POLY):237 """238 Used in Bisync, Modbus, ANSI X3.28, SIA DC-07, many others;239 Also known as CRC_16 and CRC_16-ANSI240 """241 POLY = 0x8005242 REFIN = True243 REFOUT = True244 WIDTH = 16245class CRC_16_USB:246 POLY=0x8005247 INIT=0XFFFF248 REFIN=True249 REFOUT=True250 XOROUT=0XFFFF251 CHECK=0XB4C8252 RESIDUE=0XB001253 WIDTH=16254class CRC_16_OpenSafety_A(CRC_POLY):255 "Used in safety fieldbus"256 POLY = 0x5935257 WIDTH = 16258class CRC_16_OpenSafety_B(CRC_POLY):259 "Used in safety fieldbus"260 POLY = 0x755B261 WIDTH = 16262class CRC_16_Profibus(CRC_POLY):263 "Used in fieldbus networks"264 POLY = 0x1DCF265 WIDTH = 16266class CRC_17_CAN(CRC_POLY):267 "Used in CAN FD"268 POLY = 0x1685B269 WIDTH = 17270class CRC_21_CAN(CRC_POLY):271 "Used in CAN FD"272 POLY = 0x102899273 WIDTH = 21274class CRC_24(CRC_POLY):275 "Used in FlexRay"276 POLY = 0x5D6DCB277 WIDTH = 24278class CRC_24_Radix_64(CRC_POLY):279 "Used in OpenPGP, RTCM104v3"280 POLY = 0x864CFB281 WIDTH = 24282class CRC_30(CRC_POLY):283 "Used in CDMA"284 POLY = 0x2030B9C7285 WIDTH = 30286class CRC_32(CRC_POLY):287 """288 Used in HDLC, ANSI X3.66, ITU-T V.42, Ethernet, Serial ATA,289 MPEG-2, PKZIP, Gzip, Bzip2, PNG, many others290 """291 INIT = 0xffffffff292 POLY = 0x04C11DB7293 RESIDUE = 0xC704DD7B # CBF43926294 REFIN = True295 REFOUT = True296 WIDTH = 32297 XOROUT = 0xffffffff298class CRC_32C(CRC_POLY):299 "Used in (Castagnoli), iSCSI, SCTP, G.hn payload, SSE4.2, Btrfs, ext4, Ceph"300 INIT = 0Xffffffff301 CHECK = 0xe3069283302 POLY = 0x1EDC6F41303 WIDTH = 32304 REFIN = True305 REFOUT = True306 RESIDUE = 0xb798b438307 XOROUT = 0xffffffff308class CRC_32K(CRC_POLY):309 "Koopman {1,3,28}"310 POLY = 0x741B8CD7311 WIDTH = 32312class CRC_32K_2(CRC_POLY):313 "Koopman {1,1,30}"314 POLY = 0x32583499315 WIDTH = 32316class CRC_32Q(CRC_POLY):317 "Used in aviation; AIXM"318 POLY = 0x814141AB319 WIDTH = 32320class CRC_40_GSM(CRC_POLY):321 "Used in GSM control channel[40][41]"322 POLY = 0x0004820009323 WIDTH = 40324class CRC_64_ECMA(CRC_POLY):325 "Used in ECMA-182, XZ Utils"326 POLY = 0x42F0E1EBA9EA3693327 WIDTH = 64328class CRC_64_ISO(CRC_POLY):329 "Used in HDLC, Swiss-Prot/TrEMBL; considered weak for hashing"330 POLY = 0x000000000000001B...

Full Screen

Full Screen

crc.py

Source:crc.py Github

copy

Full Screen

1def crc_check(data, div):2 l = len(div)3 ct = 04 data = [int(i) for i in data]5 div = [int(i) for i in div]6 zero = [0 for i in range(l)]7 temp_data = [data[i] for i in range(l)]8 result = []9 for j in range(len(data) - len(div) + 1):10 print("Temp_dividend", temp_data)11 msb = temp_data[0]12 if msb == 0:13 result.append(0)14 for i in range(l - 1, -1, -1):15 temp_data[i] = temp_data[i] ^ zero[i]16 else:17 result.append(1)18 for i in range(l - 1, -1, -1):19 temp_data[i] = temp_data[i] ^ div[i]20 temp_data.pop(0)21 if l + j < len(data):22 temp_data.append(data[l + j])23 crc = temp_data24 print("Quotient: ", result, "remainder", crc)25 return crc26# returning crc value27while 1 > 0:28 print("Enter data: ")29 data = input() # can use it like int(input())30 print("Enter divisor")31 div = input() # can use it like int(input())32 original_data = data33 data = data + ("0" * (len(div) - 1))34 crc = crc_check(data, div)35 crc_str = ""36 for c in crc:37 crc_str += c38 print("Sent data: ", original_data + crc_str)39 sent_data = original_data + crc_str40 print(41 "If again applying CRC algorithm, the remainder/CRC must be zero if errorless."42 )43 crc = crc_check(sent_data, div)44 remainder = crc45 print("Receiver side remainder: ", remainder)46 print("Continue [Y/N]:")47 ch = input()48 if ch == "N" or ch == "n":49 break50 else:...

Full Screen

Full Screen

crc16.py

Source:crc16.py Github

copy

Full Screen

1#!/usr/bin/python2# ======================================================================3# crc16.py - Prototype implementations of CRC16 calculation4#5# Copyright (C) 2006 Dick Streefland6#7# This is free software, licensed under the terms of the GNU General8# Public License as published by the Free Software Foundation.9# ======================================================================10import sys11polynomial = 0xA001 # X^16 + X^15 + X^2 + 1 - lower 16 bits, reversed12def crc_update(crc, value, bits):13 for bit in range(bits):14 xor = (crc ^ (value >> bit)) & 115 crc >>= 116 if xor:17 crc ^= polynomial18 return crc19def crc1(crc, byte):20 return crc_update(crc, byte, 8)21def crc4(crc, byte):22 crc = (crc >> 4) ^ tab4[(crc ^ byte) & 0xf]23 crc = (crc >> 4) ^ tab4[(crc ^ (byte >> 4)) & 0xf]24 return crc25def crc8(crc, byte):26 return (crc >> 8) ^ tab8[(crc ^ byte) & 0xff]27def crc_file(file, crcfunc):28 crc = 0xffff29 for byte in open(file).read():30 crc = crcfunc(crc, ord(byte))31 crc ^= 0xffff32 print "%02x %02x %s" % (crc & 0xff, crc >> 8, file)33tab4 = [crc_update(i, 0, 4) for i in range(2**4)]34tab8 = [crc_update(i, 0, 8) for i in range(2**8)]35for file in sys.argv[1:]:36 crc_file(file, crc1)37 crc_file(file, crc4)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful