Cyclic Redundancy Check (CRC) is used to validate data transmission. It is a ver
ID: 3834658 • Letter: C
Question
Cyclic Redundancy Check (CRC) is used to validate data transmission. It is a very simple algorithm that allows you to check if sent information over a network matches the received information over the network – essentially error checking. Both are run through the algorithm and the results are compared. Because the check value is fixed length it can also be used as a hash function. The Adler-32 is a specific algorithm that can be used for hashing or CRC. Write a Javascript algorithm to implement the Adler 32 algorithm with user input. You can use the starter shell program at https://jsfiddle.net/reaglin/mymbgqcv/ You must use fork to copy my shell to your fiddle account if you choose to use it. You will submit a link to your fiddle
Explanation / Answer
Hi,
Please find the code below. Save it in a html file and open in browser. Thanks.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
function doAdler(){
t = document.getElementById('input').value;
alert(adler32(t));
var v=adler32(t);
//showing the value in html
document.getElementById("demo").innerHTML = v;
}
function adler32(s){
var MOD_ADLER = 65521;
var a = 1;
var b = 0;
var index;
// Process each byte of the data in order
for (index = 0; index < s.length; ++index) {
a = (a + s.charCodeAt(index)) % MOD_ADLER;
b = (b + a) % MOD_ADLER;
}
//adler checksum as integer;
var adler = a | (b << 16);
//adler checksum as byte array
return String.fromCharCode(((adler >> 24) & 0xff),
((adler >> 16) & 0xff),
((adler >> 8) & 0xff),
((adler >> 0) & 0xff));
}
</script>
</head>
<body>
<input type="textbox" value="COP3530" id="input" />
<input type="button" value="Click to Calculate" />
<br />
<br />
<br />
Alder checksum:<p id="demo"></p>
</body>
</html>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.