<commit_before>;; crc16 [Crypto]
;;  Performs a Cyclic Redundancy Check on data.
;; Inputs:
;;  HL: Pointer to data
;;  BC: Size of data
;; Outputs:
;;  DE: CRC of data
crc16:
    push hl
    push bc
    ld de, 0xFFFF                        ; initialize crc
.bytelp:
        push bc                          ; save count
            ld a, (hl)                   ; fetch byte from memory
            xor d                        ; xor byte into crc top byte
            ld b, 8                      ; prepare to rotate 8 bits
.rotlp:
            sla e
            adc a, a                     ; rotate crc
            jr nc, _                     ; b15 was zero
            ld d, a                      ; put crc high byte back into d
            ld a, e \ xor 0x21 \ ld e, a ; crc=crc xor &1021, xmodem polynomic
            ld a, d \ xor 0x10           ; and get crc top byte back into a
_:          djnz .rotlp
            ld d, a                      ; put crc top byte back into d

            inc hl
        pop bc
        dec bc
        ld a, b \ or c
        jr nz, .bytelp                   ; loop until num=0
    pop bc
    pop hl
    ret

;; sha1Init [Crypto]
;;  Allocates a memory block to keep the state and result of
;;  a SHA1 hash operation.
;; Outputs:
;;  Z: Set on success, reset on failure
;;  A: Error code (on failure)
;;  IX: location of allocated block (on success)
sha1Init:
    push bc
    push de
    push hl
        ld bc, .defaultMemblock_copy_end - .defaultMemblock
        call malloc
        jr nz, .fail
        push ix \ pop de
        ld hl, .defaultMemblock
        ldir

        ; Possibly this could be improved
        push ix
            ld bc, 320 ; SHA1 block is this size
            call malloc
            ; Store the pointers
            push ix \ pop hl
        pop ix
        ld (ix + sha1_block_ptr), l
        ld (ix + sha1_block_ptr + 1), h
        ld (ix + sha1_block_front_ptr), l
        ld (ix + sha1_block_front_ptr + 1), h

        ; Success, set Z
        ld h, a
        xor a
        ld a, h
.fail:
    pop hl
    pop de
    pop bc
    ret

; This is the default memblock.  Its
; state will be changed by the algorithm.
.defaultMemblock:
sha1_hash .equ $ - .defaultMemblock
    .db $67,$45,$23,$01
    .db $EF,$CD,$AB,$89
    .db $98,$BA,$DC,$FE
    .db $10,$32,$54,$76
    .db $C3,$D2,$E1,$F0
; The length of the input is kept here
sha1_length .equ $ - .defaultMemblock
    .db $00,$00,$00,$00
    .db $00,$00,$00,$00
; Keep these contiguous
sha1_temp .equ $ - .defaultMemblock
    .block 4
sha1_a .equ $ - .defaultMemblock
    .block 4
sha1_b .equ $ - .defaultMemblock
    .block 4
sha1_c .equ $ - .defaultMemblock
    .block 4
sha1_d .equ $ - .defaultMemblock
    .block 4
sha1_e .equ $ - .defaultMemblock
    .block 4
sha1_f .equ $ - .defaultMemblock
    .block 4
sha1_k .equ $ - .defaultMemblock
    .block 4
sha1_f_op_ptr .equ $ - .defaultMemblock
    .dw $0000
.defaultMemblock_copy_end:
; Pointers to the SHA1 block are kept here
sha1_block_ptr .equ $ - .defaultMemblock
    .dw $0000
sha1_block_front_ptr .equ $ - .defaultMemblock
    .dw $0000
.defaultMemblock_end:<commit_msg>Change code style from $ to 0x<commit_after>;; crc16 [Crypto]
;;  Performs a Cyclic Redundancy Check on data.
;; Inputs:
;;  HL: Pointer to data
;;  BC: Size of data
;; Outputs:
;;  DE: CRC of data
crc16:
    push hl
    push bc
    ld de, 0xFFFF                        ; initialize crc
.bytelp:
        push bc                          ; save count
            ld a, (hl)                   ; fetch byte from memory
            xor d                        ; xor byte into crc top byte
            ld b, 8                      ; prepare to rotate 8 bits
.rotlp:
            sla e
            adc a, a                     ; rotate crc
            jr nc, _                     ; b15 was zero
            ld d, a                      ; put crc high byte back into d
            ld a, e \ xor 0x21 \ ld e, a ; crc=crc xor &1021, xmodem polynomic
            ld a, d \ xor 0x10           ; and get crc top byte back into a
_:          djnz .rotlp
            ld d, a                      ; put crc top byte back into d

            inc hl
        pop bc
        dec bc
        ld a, b \ or c
        jr nz, .bytelp                   ; loop until num=0
    pop bc
    pop hl
    ret

;; sha1Init [Crypto]
;;  Allocates a memory block to keep the state and result of
;;  a SHA1 hash operation.
;; Outputs:
;;  Z: Set on success, reset on failure
;;  A: Error code (on failure)
;;  IX: location of allocated block (on success)
sha1Init:
    push bc
    push de
    push hl
        ld bc, .defaultMemblock_copy_end - .defaultMemblock
        call malloc
        jr nz, .fail
        push ix \ pop de
        ld hl, .defaultMemblock
        ldir

        ; Possibly this could be improved
        push ix
            ld bc, 320 ; SHA1 block is this size
            call malloc
            ; Store the pointers
            push ix \ pop hl
        pop ix
        ld (ix + sha1_block_ptr), l
        ld (ix + sha1_block_ptr + 1), h
        ld (ix + sha1_block_front_ptr), l
        ld (ix + sha1_block_front_ptr + 1), h

        ; Success, set Z
        ld h, a
        xor a
        ld a, h
.fail:
    pop hl
    pop de
    pop bc
    ret

; This is the default memblock.  Its
; state will be changed by the algorithm.
.defaultMemblock:
sha1_hash .equ $ - .defaultMemblock
    .db 0x67,0x45,0x23,0x01
    .db 0xEF,0xCD,0xAB,0x89
    .db 0x98,0xBA,0xDC,0xFE
    .db 0x10,0x32,0x54,0x76
    .db 0xC3,0xD2,0xE1,0xF0
; The length of the input is kept here
sha1_length .equ $ - .defaultMemblock
    .db 0x00,0x00,0x00,0x00
    .db 0x00,0x00,0x00,0x00
; Keep these contiguous
sha1_temp .equ $ - .defaultMemblock
    .block 4
sha1_a .equ $ - .defaultMemblock
    .block 4
sha1_b .equ $ - .defaultMemblock
    .block 4
sha1_c .equ $ - .defaultMemblock
    .block 4
sha1_d .equ $ - .defaultMemblock
    .block 4
sha1_e .equ $ - .defaultMemblock
    .block 4
sha1_f .equ $ - .defaultMemblock
    .block 4
sha1_k .equ $ - .defaultMemblock
    .block 4
sha1_f_op_ptr .equ $ - .defaultMemblock
    .dw $0000
.defaultMemblock_copy_end:
; Pointers to the SHA1 block are kept here
sha1_block_ptr .equ $ - .defaultMemblock
    .dw $0000
sha1_block_front_ptr .equ $ - .defaultMemblock
    .dw $0000
.defaultMemblock_end:
{'fraction_non_alphanumeric': 0.07998106956933271, 'fraction_numerical': 0.038334122101277804, 'mean_word_length': 1.5148750495834986, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '462617', 'n_tokens_mistral': 2328, 'n_tokens_neox': 2116, 'n_words': 762}