March 2014 update

This commit is contained in:
Ingy döt Net 2014-04-02 16:56:35 +00:00
parent 09687c4926
commit a25938f123
1846 changed files with 21876 additions and 5203 deletions

View file

@ -0,0 +1,19 @@
str := "The quick brown fox jumps over the lazy dog"
MsgBox, % "String:`n" (str) "`n`nCRC32:`n" CRC32(str)
; CRC32 =============================================================================
CRC32(string, encoding = "UTF-8")
{
chrlength := (encoding = "CP1200" || encoding = "UTF-16") ? 2 : 1
length := (StrPut(string, encoding) - 1) * chrlength
VarSetCapacity(data, length, 0)
StrPut(string, &data, floor(length / chrlength), encoding)
SetFormat, Integer, % SubStr((A_FI := A_FormatInteger) "H", 0)
CRC32 := DllCall("NTDLL\RtlComputeCrc32", "UInt", 0, "UInt", &data, "UInt", length, "UInt")
CRC := SubStr(CRC32 | 0x1000000000, -7)
DllCall("User32.dll\CharLower", "Str", CRC)
SetFormat, Integer, %A_FI%
return CRC
}

View file

@ -1,13 +1,8 @@
(ql:quickload :ironclad)
(defun string-to-digest (str digest)
"Return the specified digest for the ASCII string as a hex string."
(ironclad:byte-array-to-hex-string
(ironclad:digest-sequence digest
(ironclad:ascii-string-to-byte-array str))))
(defun write-seq-base-16 (seq &key ((:stream *standard-output*)
*standard-output*)
&aux (*print-base* 16))
(map nil #'write seq))
(write-seq-base-16
(crypto:digest-sequence 'ironclad:crc32
(crypto:ascii-string-to-byte-array
"The quick brown fox jumps over the lazy dog")))
(string-to-digest "The quick brown fox jumps over the lazy dog" :crc32)

View file

@ -0,0 +1,21 @@
import Data.Bits
import Data.Word
import Numeric
crcTable :: Word32 -> Word32
crcTable i = table !! (fromIntegral i)
where
table = map (\a -> iterate xf a !! 8) [0..255]
xf r = let d = shiftR r 1 in
if r .&. 1 == 1 then xor d 0xedb88320 else d
charToWord :: Char -> Word32
charToWord c = (fromIntegral . fromEnum) c
calcCrc :: String -> Word32
calcCrc text = complement ( foldl cf (complement 0) text )
where cf crc x = xor (shiftR crc 8) (crcTable $ xor (crc .&. 0xff) (charToWord x) )
crc32 text = showHex ( calcCrc text ) ""
main = putStrLn $ crc32 "The quick brown fox jumps over the lazy dog"

View file

@ -0,0 +1,13 @@
import Data.List (genericLength)
import Numeric (showHex)
import Foreign.C
foreign import ccall "zlib.h crc32" zlib_crc32 :: CULong -> CString -> CUInt -> CULong
main = do
let s = "The quick brown fox jumps over the lazy dog"
ptr <- newCString s
let r = zlib_crc32 0 ptr (genericLength s)
putStrLn $ showHex r ""