js动画模拟加密解密

Js animation to simulate encryption decryption

我想要 运行 或伪装加密解密算法的洗牌文本。

此代码适用于数字,但我希望它适用于字符串。

<p class="count">0000000001</p>

<script>   
$('.count').each(function () {
                $(this).prop('Counter',100000000000000000).animate({
                    Counter: $(this).text()
                }, {
                    duration: 10000,
                    easing: 'swing',
                    step: function (now) {
                        $(this).text(Math.ceil(now));
                    }
                });
            });
</script>

基本方法,我会使用String.fromCharCode()随机return一个字母(97到122之间的Ascii码)和一个循环来产生最终链:

function getRandomInt(min, max) {  // whosebug.com/a/24152886/5156280
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

function returnLetter() {
  return String.fromCharCode(getRandomInt(97, 122))
}

function returnRandomString() {
  var str = ''
  for (var i = 0; i < 18; i++) {
    str += returnLetter()
  }
  return str
}

$('.count').each(function() {
  $(this).prop('Counter', 100000000000000000).animate({
    Counter: $(this).text()
  }, {
    duration: 10000,
    easing: 'swing',
    step: function (now) {                 
      $(this).text(returnRandomString());
    }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p class="count">0000000001</p>