Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
39
Task/CRC-32/F-Sharp/crc-32-1.fs
Normal file
39
Task/CRC-32/F-Sharp/crc-32-1.fs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
module Crc32 =
|
||||
|
||||
open System
|
||||
|
||||
// Generator polynomial (modulo 2) for the reversed CRC32 algorithm.
|
||||
let private s_generator = uint32 0xEDB88320
|
||||
|
||||
// Generate lookup table
|
||||
let private lutIntermediate input =
|
||||
if (input &&& uint32 1) <> uint32 0
|
||||
then s_generator ^^^ (input >>> 1)
|
||||
else input >>> 1
|
||||
|
||||
let private lutEntry input =
|
||||
{0..7}
|
||||
|> Seq.fold (fun acc x -> lutIntermediate acc) input
|
||||
|
||||
let private crc32lut =
|
||||
[uint32 0 .. uint32 0xFF]
|
||||
|> List.map lutEntry
|
||||
|
||||
let crc32byte (register : uint32) (byte : byte) =
|
||||
crc32lut.[Convert.ToInt32((register &&& uint32 0xFF) ^^^ Convert.ToUInt32(byte))] ^^^ (register >>> 8)
|
||||
|
||||
// CRC32 of a byte array
|
||||
let crc32 (input : byte[]) =
|
||||
let result = Array.fold crc32byte (uint32 0xFFFFFFFF) input
|
||||
~~~result
|
||||
|
||||
// CRC32 from ASCII string
|
||||
let crc32OfAscii (inputAscii : string) =
|
||||
let bytes = System.Text.Encoding.ASCII.GetBytes(inputAscii)
|
||||
crc32 bytes
|
||||
|
||||
// Test
|
||||
let testString = "The quick brown fox jumps over the lazy dog"
|
||||
printfn "ASCII Input: %s" testString
|
||||
let result = crc32OfAscii testString
|
||||
printfn "CRC32: 0x%x" result
|
||||
2
Task/CRC-32/F-Sharp/crc-32-2.fs
Normal file
2
Task/CRC-32/F-Sharp/crc-32-2.fs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
ASCII Input: The quick brown fox jumps over the lazy dog
|
||||
CRC32: 0x414fa339
|
||||
Loading…
Add table
Add a link
Reference in a new issue