Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
andot committed Oct 4, 2016
1 parent 8d82d48 commit f78eb05
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
18 changes: 18 additions & 0 deletions dist/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<title>XXTEA test</title>
<meta charset="UTF-8">
<script src="xxtea.min.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
var str = "asd123";
var key = "1234567890";
var encrypt_data = XXTEA.encryptToBase64(str, key);
console.log(encrypt_data);
var decrypt_data = XXTEA.decryptFromBase64(encrypt_data, key);
console.assert(str === decrypt_data);
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion dist/xxtea.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/xxtea.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
| Roger M. Needham |
| |
| Code Author: Ma Bingyao <[email protected]> |
| LastModified: Feb 21, 2016 |
| LastModified: Oct 4, 2016 |
| |
\**********************************************************/

Expand Down Expand Up @@ -330,7 +330,7 @@

function utf8DecodeLongString(bs, n) {
var buf = [];
var charCodes = new Array(0xFFFF);
var charCodes = new Array(0x8000);
var i = 0, off = 0;
for (var len = bs.length; i < n && off < len; i++) {
var unit = bs.charCodeAt(off++);
Expand Down Expand Up @@ -386,7 +386,7 @@
default:
throw new Error('Bad UTF-8 encoding 0x' + unit.toString(16));
}
if (i >= 65534) {
if (i >= 0x7FFF - 1) {
var size = i + 1;
charCodes.length = size;
buf[buf.length] = String.fromCharCode.apply(String, charCodes);
Expand All @@ -409,7 +409,7 @@
if (n === bs.length) return bs;
return bs.substr(0, n);
}
return ((n < 100000) ?
return ((n < 0xFFFF) ?
utf8DecodeShortString(bs, n) :
utf8DecodeLongString(bs, n));
}
Expand Down Expand Up @@ -450,4 +450,4 @@
decrypt: decrypt,
decryptFromBase64: decryptFromBase64
};
})(this);
})(this || [eval][0]('this'));
Loading

0 comments on commit f78eb05

Please sign in to comment.