Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
KazukiPrzyborowski authored Feb 22, 2024
1 parent 7507de1 commit 5410b67
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 21 deletions.
2 changes: 1 addition & 1 deletion catfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
$FileInfo: catfile.py - Last Update: 2/16/2024 Ver. 0.0.5 RC 1 - Author: cooldude2k $
$FileInfo: catfile.py - Last Update: 2/21/2024 Ver. 0.0.7 RC 1 - Author: cooldude2k $
'''

from __future__ import absolute_import, division, print_function, unicode_literals;
Expand Down
70 changes: 57 additions & 13 deletions checksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,46 @@
Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
$FileInfo: checksum.py - Last Update: 2/16/2024 Ver. 0.0.5 RC 1 - Author: cooldude2k $
$FileInfo: checksum.py - Last Update: 2/21/2024 Ver. 0.0.7 RC 1 - Author: cooldude2k $
'''

from __future__ import absolute_import, division, print_function, unicode_literals;
import os, binascii, argparse, shutil, hashlib, zlib;
from io import open as open;

chksum_list = sorted(['adler32', 'crc16', 'crc32']);
chksum_list_hash = sorted(list(hashlib.algorithms_guaranteed));
chksum_list = sorted(['adler32', 'crc16', 'crc16_ansi', 'crc16_ibm', 'crc16_ccitt', 'crc32', 'crc64', 'crc64_ecma', 'crc64_iso']);
#chksum_list_hash = sorted(list(hashlib.algorithms_guaranteed));
chksum_list_hash = sorted(list(hashlib.algorithms_available));

def crc16(msg):
# initial_value can be 0xFFFF or 0x0000
def crc16_ansi(msg, initial_value=0xFFFF):
# CRC-16-IBM / CRC-16-ANSI polynomial and initial value
poly = 0x8005; # Polynomial for CRC-16-IBM / CRC-16-ANSI
crc = 0xFFFF; # Initial value
crc = initial_value; # Initial value
for b in msg:
crc ^= b << 8; # XOR byte into CRC top byte
for _ in range(8): # Process each bit
if crc & 0x8000: # If the top bit is set
crc = (crc << 1) ^ poly; # Shift left and XOR with the polynomial
else:
crc = crc << 1; # Just shift left
crc &= 0xFFFF; # Ensure CRC remains 16-bit
return crc;

# initial_value can be 0xFFFF or 0x0000
def crc16_ibm(msg, initial_value=0xFFFF):
return crc16_ansi(msg, initial_value);

# initial_value is 0xFFFF
def crc16(msg):
return crc16_ansi(msg, 0xFFFF);

# initial_value can be 0xFFFF, 0x1D0F or 0x0000
def crc16_ccitt(msg, initial_value=0xFFFF):
# CRC-16-CCITT polynomial
poly = 0x1021; # Polynomial for CRC-16-CCITT
# Use the specified initial value
crc = initial_value;
for b in msg:
crc ^= b << 8; # XOR byte into CRC top byte
for _ in range(8): # Process each bit
Expand All @@ -38,10 +64,11 @@ def crc16(msg):
crc &= 0xFFFF; # Ensure CRC remains 16-bit
return crc;

def crc64_ecma(msg):
# initial_value can be 0x42F0E1EBA9EA3693 or 0x0000000000000000
def crc64_ecma(msg, initial_value=0x0000000000000000):
# CRC-64-ECMA polynomial and initial value
poly = 0x42F0E1EBA9EA3693;
crc = 0x0000000000000000; # Initial value for CRC-64-ECMA
crc = initial_value; # Initial value for CRC-64-ECMA
for b in msg:
crc ^= b << 56; # XOR byte into the most significant byte of the CRC
for _ in range(8): # Process each bit
Expand All @@ -52,10 +79,11 @@ def crc64_ecma(msg):
crc &= 0xFFFFFFFFFFFFFFFF; # Ensure CRC remains 64-bit
return crc;

def crc64_iso(msg):
# initial_value can be 0x000000000000001B or 0xFFFFFFFFFFFFFFFF
def crc64_iso(msg, initial_value=0xFFFFFFFFFFFFFFFF):
# CRC-64-ISO polynomial and initial value
poly = 0x000000000000001B;
crc = 0xFFFFFFFFFFFFFFFF; # Common initial value for CRC-64-ISO
crc = initial_value; # Common initial value for CRC-64-ISO
for b in msg:
crc ^= b << 56; # XOR byte into the most significant byte of the CRC
for _ in range(8): # Process each bit
Expand All @@ -66,11 +94,19 @@ def crc64_iso(msg):
crc &= 0xFFFFFFFFFFFFFFFF; # Ensure CRC remains 64-bit
return crc;

def crc16_file(infile):
def crc16_ansi_file(infile):
if(not os.path.exists(infile) or not os.path.isfile(infile)):
return False;
filefp = open(infile, "rb");
checksum = format(crc16(filefp.read()) & 0xffff, '04x').lower();
checksum = format(crc16_ansi(filefp.read()) & 0xffff, '04x').lower();
filefp.close();
return checksum;

def crc16_ccitt_file(infile):
if(not os.path.exists(infile) or not os.path.isfile(infile)):
return False;
filefp = open(infile, "rb");
checksum = format(crc16_ccitt(filefp.read()) & 0xffff, '04x').lower();
filefp.close();
return checksum;

Expand Down Expand Up @@ -128,7 +164,15 @@ def hash_file(infile, checksumtype):
if(getargs.checksum not in chksum_list + chksum_list_hash):
exit();
if(getargs.checksum in chksum_list):
if(getargs.checksum=="crc16"):
if(getargs.checksum=="crc16_ansi" or getargs.checksum=="crc16_ibm" or getargs.checksum=="crc16"):
outchck = crc16_file(getargs.input);
if(not outchck):
exit();
if(not getargs.quiet):
print(str(outchck)+" *"+getargs.input);
else:
print(str(outchck));
if(getargs.checksum=="crc16_ccitt"):
outchck = crc16_file(getargs.input);
if(not outchck):
exit();
Expand Down Expand Up @@ -160,7 +204,7 @@ def hash_file(infile, checksumtype):
print(str(outchck)+" *"+getargs.input);
else:
print(str(outchck));
if(getargs.checksum=="crc64_iso"):
if(getargs.checksum=="crc64_iso" or getargs.checksum=="crc64"):
outchck = crc64_iso_file(getargs.input);
if(not outchck):
exit();
Expand Down
2 changes: 1 addition & 1 deletion compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
$FileInfo: compression.py - Last Update: 2/16/2024 Ver. 0.0.5 RC 1 - Author: cooldude2k $
$FileInfo: compression.py - Last Update: 2/21/2024 Ver. 0.0.7 RC 1 - Author: cooldude2k $
'''

from __future__ import absolute_import, division, print_function, unicode_literals;
Expand Down
2 changes: 1 addition & 1 deletion mkcatfilebundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
$FileInfo: mkbundle.py - Last Update: 2/16/2024 Ver. 0.0.5 RC 1 - Author: cooldude2k $
$FileInfo: mkbundle.py - Last Update: 2/21/2024 Ver. 0.0.7 RC 1 - Author: cooldude2k $
'''

import os, sys, shutil, subprocess, tempfile, subprocess, platform;
Expand Down
2 changes: 1 addition & 1 deletion phpcatfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
$FileInfo: phpcatfile.php - Last Update: 2/16/2024 Ver. 0.0.5 RC 1 - Author: cooldude2k $
$FileInfo: phpcatfile.php - Last Update: 2/21/2024 Ver. 0.0.7 RC 1 - Author: cooldude2k $
*/

date_default_timezone_set('UTC');
Expand Down
2 changes: 1 addition & 1 deletion pycatfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
$FileInfo: pycatfile.py - Last Update: 2/16/2024 Ver. 0.0.5 RC 1 - Author: cooldude2k $
$FileInfo: pycatfile.py - Last Update: 2/21/2024 Ver. 0.0.7 RC 1 - Author: cooldude2k $
'''

from __future__ import absolute_import, division, print_function, unicode_literals;
Expand Down
2 changes: 1 addition & 1 deletion pyshell-old.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
$FileInfo: pyshell-old.py - Last Update: 2/16/2024 Ver. 0.0.5 RC 1 - Author: cooldude2k $
$FileInfo: pyshell-old.py - Last Update: 2/21/2024 Ver. 0.0.7 RC 1 - Author: cooldude2k $
'''

from __future__ import print_function
Expand Down
2 changes: 1 addition & 1 deletion pyshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Copyright 2018-2024 Game Maker 2k - http://intdb.sourceforge.net/
Copyright 2018-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
$FileInfo: pyshell.py - Last Update: 2/16/2024 Ver. 0.0.5 RC 1 - Author: cooldude2k $
$FileInfo: pyshell.py - Last Update: 2/21/2024 Ver. 0.0.7 RC 1 - Author: cooldude2k $
'''

from __future__ import division, absolute_import, print_function;
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Copyright 2016-2024 Game Maker 2k - http://intdb.sourceforge.net/
Copyright 2016-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
$FileInfo: setup.py - Last Update: 2/16/2024 Ver. 0.0.5 RC 1 - Author: cooldude2k $
$FileInfo: setup.py - Last Update: 2/21/2024 Ver. 0.0.7 RC 1 - Author: cooldude2k $
'''

import os, re, sys, pkg_resources;
Expand Down

0 comments on commit 5410b67

Please sign in to comment.