Python

No description

fork
loading
Files
  • main.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.8809011234698052","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"IyBIZWxwZXIgRnVuY3Rpb24NCmRlZiBiaW5hcnkoc3RyaW5nKToNCglhbnN3ZXIgPSBbXQ0KCWZvciBpIGluIHN0cmluZzoNCgkJYW5zd2VyLmFwcGVuZChib29sKGludChpKSkpDQoJcmV0dXJuIGFuc3dlcg0KDQpkZWYgc3RyaW5nKGJpbmFyeSk6DQoJYW5zd2VyID0gIiINCglmb3IgaSBpbiBiaW5hcnk6DQoJCWFuc3dlciArPSBzdHIoaW50KGkpKQ0KCXJldHVybiBhbnN3ZXINCg0KIyBDb25maWd1cmF0aW9uIENvbnN0YW50cw0KZGVmIENvbmZpZyhwb2x5LCBpbml0PU5vbmUsIHJlZl9pbj1GYWxzZSwgcmVmX291dD1GYWxzZSwgeG9yX291dD1Ob25lKToNCiAgaWYgaW5pdCA9PSBOb25lOiBpbml0ID0gW0ZhbHNlXSAqIGxlbihwb2x5KQ0KICBpZiB4b3Jfb3V0ID09IE5vbmU6IHhvcl9vdXQgPSBbRmFsc2VdICogbGVuKHBvbHkpDQogIHJldHVybiB7DQogICAgInBvbHkiOiBwb2x5LA0KICAgICJpbml0IjogaW5pdCwNCiAgICAicmVmX2luIjogcmVmX2luLA0KICAgICJyZWZfb3V0IjogcmVmX291dCwNCiAgICAieG9yX291dCI6IHhvcl9vdXQNCiAgfQ0KDQpDUkNfOCA9IENvbmZpZyhwb2x5PWJpbmFyeSgiMDAwMDAxMTEiKSkNCkNSQ184X0NETUEyMDAwID0gQ29uZmlnKHBvbHk9YmluYXJ5KCIxMDAxMTAxMSIpLCBpbml0PWJpbmFyeSgiMTExMTExMTEiKSkNCkNSQ184X0RBUkMgPSANCiNDUkNfOF9EVkJfUzIgPSANCiNDUkNfOF9FQlUgPSANCiNDUkNfOF9JX0NPREUgPSANCiNDUkNfOF9JVFUgPSANCiNDUkNfOF9NQVhJTSA9IA0KI0NSQ184X1JPSEMgPSANCiNDUkNfOF9XQ0RNQSA9IA0KDQpDUkNfMTZfWE1PREVNID0gQ29uZmlnKHBvbHk9YmluYXJ5KCIwMDAxMDAwMDAwMTAwMDAxIikpDQoNCiMgQ1JDIENhbGN1bGF0b3INCmRlZiBjcmMobWVzc2FnZV8sIGNvbmZpZywgZGVidWc9RmFsc2UpOg0KICBkaXZpc29yID0gW1RydWVdICsgY29uZmlnWyJwb2x5Il0NCiAgbGVuZ3RoID0gbGVuKGRpdmlzb3IpDQogIG1lc3NhZ2UgPSBiaW5hcnkobWVzc2FnZV8pICsgKFtGYWxzZV0gKiAobGVuZ3RoLTEpKQ0KICBpZiBkZWJ1ZzogcHJpbnQoc3RyaW5nKGRpdmlzb3IpKQ0KICB3aGlsZSBsZW4obWVzc2FnZSkgPj0gbGVuZ3RoOg0KICAgIGlmIG1lc3NhZ2VbMF06DQogICAgICBmb3IgaSBpbiByYW5nZShsZW5ndGgpOg0KICAgICAgICBpZiBkaXZpc29yW2ldOg0KICAgICAgICAgIG1lc3NhZ2VbaV0gPSBub3QgbWVzc2FnZVtpXQ0KICAgIGlmIGRlYnVnOiBwcmludChzdHJpbmcobWVzc2FnZSkpDQogICAgbWVzc2FnZSA9IG1lc3NhZ2VbMTpdDQogIHJldHVybiBzdHJpbmcobWVzc2FnZSk="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Helper Function
def binary(string):
	answer = []
	for i in string:
		answer.append(bool(int(i)))
	return answer

def string(binary):
	answer = ""
	for i in binary:
		answer += str(int(i))
	return answer

# Configuration Constants
def Config(poly, init=None, ref_in=False, ref_out=False, xor_out=None):
  if init == None: init = [False] * len(poly)
  if xor_out == None: xor_out = [False] * len(poly)
  return {
    "poly": poly,
    "init": init,
    "ref_in": ref_in,
    "ref_out": ref_out,
    "xor_out": xor_out
  }

CRC_8 = Config(poly=binary("00000111"))
CRC_8_CDMA2000 = Config(poly=binary("10011011"), init=binary("11111111"))
CRC_8_DARC = 
#CRC_8_DVB_S2 = 
#CRC_8_EBU = 
#CRC_8_I_CODE = 
#CRC_8_ITU = 
#CRC_8_MAXIM = 
#CRC_8_ROHC = 
#CRC_8_WCDMA = 

CRC_16_XMODEM = Config(poly=binary("0001000000100001"))

# CRC Calculator
def crc(message_, config, debug=False):
  divisor = [True] + config["poly"]
  length = len(divisor)
  message = binary(message_) + ([False] * (length-1))
  if debug: print(string(divisor))
  while len(message) >= length:
    if message[0]:
      for i in range(length):
        if divisor[i]:
          message[i] = not message[i]
    if debug: print(string(message))
    message = message[1:]
  return string(message)