O bom desse script é que, como podemos analisa-lo linha por linha, temos certeza de que não há nenhum trojan embutido e ele funciona off-line. Para fazer, basta copiar o código-fonte e colar no bloco de notas. Em seguida, salvar com o nome que você quiser e extensão "htm" ou "html". Pode ser, pro exemplo "crypto.htm".
Segue o código-fonte.
<html>
<body>
<script type="text/javascript">
function encrypt(origin, size, key, word){
var s = 0
for (var i = 0; i < key.length; i++) {
s = s + key.charCodeAt(i)
}
var e = ''
var pos = 0
var shift= s % word.length;
for (var i = 0; i < word.length; i++) {
var j = (i + shift) % word.length;
e = e + String.fromCharCode((word.charCodeAt(j) - origin + key.charCodeAt(pos) - origin) % size + origin);
pos = (pos + 1) % key.length
}
return e;
}
function decrypt(origin, size, key, word) {
var s = 0
for (var i = 0; i < key.length; i++) {
s = s + key.charCodeAt(i)
}
var pos = 0
var first = s % word.length
var prefix = ''
var suffix = ''
for (var i = 0; i < word.length - first; i++) {
suffix = suffix + String.fromCharCode((word.charCodeAt(i) + size - key.charCodeAt(pos)) % size+ origin)
pos = (pos + 1) % key.length
}
for (var i = word.length - first; i < word.length; i++) {
prefix = prefix + String.fromCharCode((word.charCodeAt(i) + size - key.charCodeAt(pos)) % size + origin)
pos = (pos + 1) % key.length
}
var d = prefix + suffix
return d;
}
function doEncryption(origin, size, key, word, context, continuation){
continuation(context, encrypt(origin, size, key, word));
}
function doDecryption(origin, size, key, word, context, continuation){
continuation(context, decrypt(origin, size, key, word));
}
</script>
<form id="vigenere">
First character (ASCII code):
<input type="text" id="originV" placeholder="32" value="32" size="10"><br>
Size of the alphabet:
<input type="text" id="sizeV" placeholder="256" value="256" size="10"><br>
Key:
<input type="text" id="key" value=""><br>
Message:
<input type="text" id="word" value="" size="100"><br>
<input class="button" type="button" id="encryption" value="Encrypt"
onClick="doEncryption(parseInt(this.form.originV.value),
parseInt(this.form.sizeV.value),
this.form.key.value,
this.form.word.value, this.form,
function(f, t){
f.result.value = t;
})">
<input type="text" id="result" value="" size="100"><br>
<input class="button" type="button" id="decryption" value="Decrypt"
onClick="doDecryption(parseInt(this.form.originV.value),
parseInt(this.form.sizeV.value),
this.form.key.value,
this.form.result.value, this.form,
function(f, t){
f.initial.value = t;
})">
<input type="text" id="initial" value="" size="100">
</form>
</body>
</html>
Nenhum comentário:
Postar um comentário