35 lines
No EOL
2.4 KiB
HTML
35 lines
No EOL
2.4 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>Hash.crc32 — Ludic</title>
|
||
<meta name="description" content="CRC-32 checksum for corruption detection.">
|
||
<link rel="stylesheet" href="base.css">
|
||
<link rel="stylesheet" href="docs.css">
|
||
</head>
|
||
<body>
|
||
<header class="nav"><div class="wrap nav-in"><a class="brand" href="index.html"><span class="logo">L</span> Ludic</a><button class="nav-toggle" aria-label="Toggle menu" aria-expanded="false">☰</button><nav class="nav-links"><a href="index.html">Home</a><a href="api.html">API Reference</a><a class="nav-cta" href="https://git.workshopsoft.io/workshopsoft/ludic">Source ↗</a></nav></div></header>
|
||
<main class="wrap item">
|
||
<div class="crumbs"><a href="api.html">API Reference</a> <span>›</span> <a href="ns-hash.html">Hash</a> <span>›</span> <span class="here">Hash.crc32</span></div>
|
||
<div class="item-head">
|
||
<span class="kind-badge kind-method">method</span>
|
||
<h1 id="top">Hash.crc32</h1>
|
||
</div>
|
||
<code class="sig">Hash.crc32(s) -> int</code>
|
||
<div class="desc"><p>The <a href="https://en.wikipedia.org/wiki/Cyclic_redundancy_check">CRC-32</a> checksum of a string's bytes — the standard IEEE 802.3 variant (reflected polynomial <code>0xEDB88320</code>), the same one used by zip, gzip and PNG. Its well-known check value: <code>Hash.crc32("123456789")</code> is <code>0xCBF43926</code>. Use it to catch accidental corruption in a save file, downloaded asset, or config blob: store the checksum alongside the data and compare on load. It detects damage, not tampering — an attacker can trivially forge a matching CRC, so it is not a security check (see the section note).</p></div>
|
||
<div class="params"><h2>Parameters</h2><div class="param" id="param-s"><code class="pname">s</code><span class="pdesc">the string (bytes) to checksum</span></div></div>
|
||
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program Checksum {
|
||
entry {
|
||
let data = "save:level=3;coins=120"
|
||
let ck = Hash.crc32(data) # store this next to the save; recompute on load
|
||
print(ck)
|
||
print(Hash.crc32(data) == ck) # 1 — unchanged data checks out
|
||
}
|
||
}</pre></div>
|
||
|
||
<a class="back" href="api.html">← All symbols</a>
|
||
</main>
|
||
<script src="ludic-highlight.js"></script>
|
||
<script>Ludic.highlightAll(); Ludic.installCards(); Ludic.flashTarget();</script>
|
||
</body></html> |