September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
50
Task/CRC-32/FreeBASIC/crc-32.freebasic
Normal file
50
Task/CRC-32/FreeBASIC/crc-32.freebasic
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
' version 18-03-2017
|
||||
' compile with: fbc -s console
|
||||
|
||||
Function crc32(buf As String) As UInteger<32>
|
||||
|
||||
Static As UInteger<32> table(256)
|
||||
Static As UInteger<32> have_table
|
||||
Dim As UInteger<32> crc, k
|
||||
Dim As ULong i, j
|
||||
|
||||
If have_table = 0 Then
|
||||
For i = 0 To 255
|
||||
k = i
|
||||
For j = 0 To 7
|
||||
If (k And 1) Then
|
||||
k Shr= 1
|
||||
k Xor= &Hedb88320
|
||||
Else
|
||||
k Shr= 1
|
||||
End If
|
||||
table(i) = k
|
||||
Next
|
||||
Next
|
||||
have_table = 1
|
||||
End If
|
||||
|
||||
crc = Not crc ' crc = &Hffffffff
|
||||
|
||||
For i = 0 To Len(buf) -1
|
||||
crc = (crc Shr 8) Xor table((crc And &hff) Xor buf[i])
|
||||
Next
|
||||
|
||||
Return Not crc
|
||||
|
||||
End Function
|
||||
|
||||
' ------=< MAIN >=------
|
||||
|
||||
Dim As String l = "The quick brown fox jumps over the lazy dog"
|
||||
Dim As UInteger<32> crc
|
||||
|
||||
Print "input = "; l
|
||||
print
|
||||
Print "The CRC-32 checksum = "; Hex(crc32(l), 8)
|
||||
|
||||
' empty keyboard buffer
|
||||
While Inkey <> "" : Wend
|
||||
Print : Print "hit any key to end program"
|
||||
Sleep
|
||||
End
|
||||
12
Task/CRC-32/Kotlin/crc-32.kotlin
Normal file
12
Task/CRC-32/Kotlin/crc-32.kotlin
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
// version 1.0.6
|
||||
|
||||
import java.util.zip.CRC32
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val text = "The quick brown fox jumps over the lazy dog"
|
||||
val crc = CRC32()
|
||||
with (crc) {
|
||||
update(text.toByteArray())
|
||||
println("The CRC-32 checksum of '$text' = ${"%x".format(value)}")
|
||||
}
|
||||
}
|
||||
9
Task/CRC-32/OoRexx/crc-32.rexx
Normal file
9
Task/CRC-32/OoRexx/crc-32.rexx
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/* ooRexx */
|
||||
clzCRC32=bsf.importClass("java.util.zip.CRC32")
|
||||
myCRC32 =clzCRC32~new
|
||||
toBeEncoded="The quick brown fox jumps over the lazy dog"
|
||||
myCRC32~update(BsfRawBytes(toBeEncoded))
|
||||
numeric digits 20
|
||||
say 'The CRC-32 value of "'toBeEncoded'" is:' myCRC32~getValue~d2x
|
||||
|
||||
::requires "BSF.CLS" -- get Java bridge
|
||||
|
|
@ -8,7 +8,7 @@ sub crc(
|
|||
:@bitorder = 0..7, # default: eat bytes LSB-first
|
||||
:@crcorder = 0..$n-1, # default: MSB of checksum is coefficient of x⁰
|
||||
) {
|
||||
my @bit = flat ($buf.list X+& (1 X+< @bitorder).list)».so».Int, 0 xx $n;
|
||||
my @bit = flat ($buf.list X+& (1 X+< @bitorder))».so».Int, 0 xx $n;
|
||||
|
||||
@bit[0 .. $n-1] «+^=» @init;
|
||||
@bit[$_ ..$_+$n] «+^=» @poly if @bit[$_] for 0..@bit.end-$n;
|
||||
|
|
|
|||
29
Task/CRC-32/Visual-Basic-.NET/crc-32-1.visual
Normal file
29
Task/CRC-32/Visual-Basic-.NET/crc-32-1.visual
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
Public Class Crc32
|
||||
|
||||
' Table for pre-calculated values.
|
||||
Shared table(255) As UInteger
|
||||
|
||||
' Initialize table
|
||||
Shared Sub New()
|
||||
For i As UInteger = 0 To table.Length - 1
|
||||
Dim te As UInteger = i ' table entry
|
||||
For j As Integer = 0 To 7
|
||||
If (te And 1) = 1 Then te = (te >> 1) Xor &HEDB88320UI Else te >>= 1
|
||||
Next
|
||||
table(i) = te
|
||||
Next
|
||||
End Sub
|
||||
|
||||
' Return checksum calculation for Byte Array,
|
||||
' optionally resuming (used when breaking a large file into read-buffer-sized blocks).
|
||||
' Call with Init = False to continue calculation.
|
||||
Public Shared Function cs(BA As Byte(), Optional Init As Boolean = True) As UInteger
|
||||
Static crc As UInteger
|
||||
If Init Then crc = UInteger.MaxValue
|
||||
For Each b In BA
|
||||
crc = (crc >> 8) Xor table((crc And &HFF) Xor b)
|
||||
Next
|
||||
Return Not crc
|
||||
End Function
|
||||
|
||||
End Class
|
||||
23
Task/CRC-32/Visual-Basic-.NET/crc-32-2.visual
Normal file
23
Task/CRC-32/Visual-Basic-.NET/crc-32-2.visual
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
' Returns a Byte Array from a string of ASCII characters.
|
||||
Function Str2BA(Str As String) As Byte()
|
||||
Return System.Text.Encoding.ASCII.GetBytes(Str)
|
||||
End Function
|
||||
|
||||
' Returns a Hex string from an UInteger, formatted to a number of digits,
|
||||
' adding leading zeros If necessary.
|
||||
Function HexF(Value As UInteger, Digits As Integer) As String
|
||||
HexF = Hex(Value)
|
||||
If Len(HexF) < Digits Then HexF = StrDup(Digits - Len(HexF), "0") & HexF
|
||||
End Function
|
||||
|
||||
' Tests Crc32 class
|
||||
Sub Test()
|
||||
Dim Str As String = "The quick brown fox jumps over the lazy dog"
|
||||
Debug.Print("Input = """ & Str & """")
|
||||
' Convert string to Byte Array, compute crc32, and display formatted result
|
||||
Debug.Print("Crc32 = " & HexF(Crc32.cs(Str2BA(Str)), 8))
|
||||
' This next code demonstrates continuing a crc32 calculation when breaking the input
|
||||
' into pieces, such as processing a large file by a series of buffer reads.
|
||||
Crc32.cs(Str2BA(Mid(Str, 1, 20)))
|
||||
Debug.Print("Crc32 = " & HexF(Crc32.cs(Str2BA(Mid(Str, 21)), False), 8))
|
||||
End Sub
|
||||
3
Task/CRC-32/Visual-Basic-.NET/crc-32-3.visual
Normal file
3
Task/CRC-32/Visual-Basic-.NET/crc-32-3.visual
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Input = "The quick brown fox jumps over the lazy dog"
|
||||
Crc32 = 414FA339
|
||||
Crc32 = 414FA339
|
||||
3
Task/CRC-32/Zkl/crc-32.zkl
Normal file
3
Task/CRC-32/Zkl/crc-32.zkl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
var [const] ZLib=Import("zeelib");
|
||||
ZLib.calcCRC32(Data(Void,"The quick brown fox jumps over the lazy dog"));
|
||||
//-->0x414fa339
|
||||
Loading…
Add table
Add a link
Reference in a new issue