导航

萌即是正义!时不时分享一些ACG活动记录与有趣代码的小站!

侧边栏
热门文章
1推文
2025年4月19日,天气晴,今天去六本木参观手塚治虫《火之鸟》展。 展览设在六本木著名的观景台里,一边看展览,一边还能从52层俯瞰整个东京的景色,所以特地选了傍晚时分,正好能看着东京由白天渐渐过渡到夜晚的模样,夜景非常漂亮。 不过稍微有点可惜,展览本身禁止拍摄,只能在入口处拍几张留念。 展出的内容以手塚治虫老师《火之鸟》的手稿为主,按照各个篇章的顺序,介绍了每个篇章的大致剧情和设定背景。 不愧是手塚治虫老师的神作,从这些设定与故事脉络里,能清晰看到如今许多动漫与影视作品的影子,堪称现代剧情内容创作的开山鼻祖。 如果有机会,真的很推荐亲自看看,感受一下那个时代孕育出的不朽之作。
热度
349
2页面
活动
热度
273
3页面
程序员老黄历&求签
热度
234
4博文
探访《蜡笔小新》老家——春日部游记
热度
221
5推文
日本著名的博客平台goo blog宣布2025年11月18日停止服务。 很可惜呀,这个博客平台存有大量日本圣地巡礼的内容。随着goo blog的停止,圣地巡礼尤其是老作品的圣地巡礼的资料将会迎来断崖式的减少。
热度
182
6推文
今天去看了首部初音未来的电影《剧场版 世界计划 破碎的世界与无法歌唱的未来》。 说是初音未来的电影,但其实是手游《世界计划》的剧场版。好像有挺多人看到是初音未来的电影就去看了,结果发现并不全是😅。其实在宣传海报中,初音未来后面的那些人才是主角。 不过,我也是那些没玩过手游的观众之一。其实整场看下来问题也不是很大,就是对于人物关系和世界观的设定可能会有些问题。电影其实也很贴心地在剧情开头,大致以剧情的形式展示了手游中的五个团体的人物及其性格,但感觉还是有些杯水车薪,约等于看个眼熟。 此次的电影是第一次购买应援场。所谓的应援场,就是能在电影院里像是听演唱会一样挥舞荧光棒和尽情呐喊。看着前排那些粉丝看到自己喜欢角色时的呐喊,以及演唱会环节的打CALL,应援场确实是很有意思的一种电影观看方式呢! 剧情方面,属于看了开头大概能猜到整部动画的剧情走向。不过,通过演唱会的气氛渲染,甚至还感受到了一丝丝的感动。 总体来说,对于手游的粉丝来说可能是嘉年华般的狂喜,对于没接触过手游的路人来说也能一定程度融入其中,属于一部不错的粉丝向电影(不管是手游粉丝还是初音未来粉丝)。 首周电影特典是CD和游戏内的兑换码。送CD这种形式还第一次遇到,官方大气!
热度
143
7推文
从52层的六本木观景台俯瞰东京的夜景,真的非常漂亮! 还遇到了不知道哪里正在烟花表演,使得景色更加美丽了!
热度
142
8页面
友链
热度
117
9博文
真相永远只有一个!《名侦探柯南》特别音乐会2025
热度
104
10页面
游戏
热度
104
最新评论
广树管理员
2025-04-19 21:48
@粽叶加米:是这样的,现在主线推进非常非常慢
广树管理员
2025-04-19 21:47
@AlexMa233:Wayback Machine 查询前需要知道URL,届时都不知道怎么搜索
粽叶加米
2025-04-19 17:04
当时回想起为什么断追,可能是主线推进太慢~
AlexMa233
2025-04-19 15:11
有数据迁移服务,但是只能迁移评论和博文,并且要本人转移 没有完整的归档公开 但是Wayback Machine应该可以保存大部分的内容
广树管理员
2025-04-18 21:49
@Zrzzz:其实更直观点还可以传全景视频,只不过不想露脸。
攻略中
星空列车与白的旅行
暂无评分
Steam星空列车与白的旅行
2025年2月22日 22时 ~ 攻略中
已累计游玩1个月26天
乘坐的列车,划破夜空,飞驰在星空之下,令人心旷神怡——这可真是场超值之旅。舒爽夜风吹拂下的随心独旅中,我邂逅了随性的乘客,可人怜爱的乘务员。以及……猫耳少女?这场旅行,究竟会在她身上,留下了些什么呢?
界之轨迹
暂无评分
PS5界之轨迹
2024年9月28日 14时 ~ 攻略中
已累计游玩6个月23天
导力之父爱普斯泰因预言的世界末日即将到来,此时东大陆共和国所研发的导力火箭划破天空,即将探访这个世界的边界。 与此同时万事屋的青年们,正聚集在奥雷德自治州,与集结而来的各方势力,一同看望着这科技奇点。 人们这次是否能认识到世界的真实呢?
PSN奖杯卡

PSN奖杯卡

归档
赞助商广告

【JavaScript 笔记】base58加密解密 & 字符串转二进制数组 & ascii码转字符 & Hash sha256加密输出ascii字符

作者:广树时间:2018-03-21 10:50:24分类:JavaScript

base58加密解密:

var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
var ALPHABET_MAP = {}
for(var i = 0; i < ALPHABET.length; i++) {
  ALPHABET_MAP[ALPHABET.charAt(i)] = i
}
var BASE = 58

function encode(buffer) {
  if (buffer.length === 0) return ''

  var i, j, digits = [0]
  for (i = 0; i < buffer.length; i++) {
    for (j = 0; j < digits.length; j++) digits[j] <<= 8

    digits[0] += buffer[i]

    var carry = 0
    for (j = 0; j < digits.length; ++j) {
      digits[j] += carry

      carry = (digits[j] / BASE) | 0
      digits[j] %= BASE
    }

    while (carry) {
      digits.push(carry % BASE)

      carry = (carry / BASE) | 0
    }
  }

  // deal with leading zeros
  for (i = 0; buffer[i] === 0 && i < buffer.length - 1; i++) digits.push(0)

  return digits.reverse().map(function(digit) { return ALPHABET[digit] }).join('')
}

function decode(string) {
  if (string.length === 0) return []

  var i, j, bytes = [0]
  for (i = 0; i < string.length; i++) {
    var c = string[i]
    if (!(c in ALPHABET_MAP)) throw new Error('Non-base58 character')

    for (j = 0; j < bytes.length; j++) bytes[j] *= BASE
    bytes[0] += ALPHABET_MAP[c]

    var carry = 0
    for (j = 0; j < bytes.length; ++j) {
      bytes[j] += carry

      carry = bytes[j] >> 8
      bytes[j] &= 0xff
    }

    while (carry) {
      bytes.push(carry & 0xff)

      carry >>= 8
    }
  }

  // deal with leading zeros
  for (i = 0; string[i] === '1' && i < string.length - 1; i++) bytes.push(0)

  return bytes.reverse()
}

encode(buffer)//加密
decode(string)//解密


字符串转二进制数组:

function stringToBytes(str) {
      var ch, st, re = [];
      for (var i = 0; i < str.length; i++) {
        ch = str.charCodeAt(i);  // get char  
        st = [];                 // set up "stack"  

        do {
          st.push(ch & 0xFF);  // push byte to stack  
          ch = ch >> 8;          // shift value down by 1 byte  
        }

        while (ch);
        // add stack contents to result  
        // done because chars have "wrong" endianness  
        re = re.concat(st.reverse());
      }
      // return an array of bytes  
      return re;
}

stringToBytes(str)


ascii码转字符:

String.fromCharCode(number)


Hash sha256加密输出ascii字符:

function sha256(ascii) {
      function rightRotate(value, amount) {
        return (value >>> amount) | (value << (32 - amount));
      };

      var mathPow = Math.pow;
      var maxWord = mathPow(2, 32);
      var lengthProperty = 'length'
      var i, j; // Used as a counter across the whole file
      var result = ''

      var words = [];
      var asciiBitLength = ascii[lengthProperty] * 8;

      //* caching results is optional - remove/add slash from front of this line to toggle
      // Initial hash value: first 32 bits of the fractional parts of the square roots of the first 8 primes
      // (we actually calculate the first 64, but extra values are just ignored)
      var hash = sha256.h = sha256.h || [];
      // Round constants: first 32 bits of the fractional parts of the cube roots of the first 64 primes
      var k = sha256.k = sha256.k || [];
      var primeCounter = k[lengthProperty];
      /*/
      var hash = [], k = [];
      var primeCounter = 0;
      //*/

      var isComposite = {};
      for (var candidate = 2; primeCounter < 64; candidate++) {
        if (!isComposite[candidate]) {
          for (i = 0; i < 313; i += candidate) {
            isComposite[i] = candidate;
          }
          hash[primeCounter] = (mathPow(candidate, .5) * maxWord) | 0;
          k[primeCounter++] = (mathPow(candidate, 1 / 3) * maxWord) | 0;
        }
      }

      ascii += '\x80' // Append Ƈ' bit (plus zero padding)
      while (ascii[lengthProperty] % 64 - 56) ascii += '\x00' // More zero padding
      for (i = 0; i < ascii[lengthProperty]; i++) {
        j = ascii.charCodeAt(i);
        if (j >> 8) return; // ASCII check: only accept characters in range 0-255
        words[i >> 2] |= j << ((3 - i) % 4) * 8;
      }
      words[words[lengthProperty]] = ((asciiBitLength / maxWord) | 0);
      words[words[lengthProperty]] = (asciiBitLength)

      // process each chunk
      for (j = 0; j < words[lengthProperty];) {
        var w = words.slice(j, j += 16); // The message is expanded into 64 words as part of the iteration
        var oldHash = hash;
        // This is now the undefinedworking hash", often labelled as variables a...g
        // (we have to truncate as well, otherwise extra entries at the end accumulate
        hash = hash.slice(0, 8);

        for (i = 0; i < 64; i++) {
          var i2 = i + j;
          // Expand the message into 64 words
          // Used below if 
          var w15 = w[i - 15], w2 = w[i - 2];

          // Iterate
          var a = hash[0], e = hash[4];
          var temp1 = hash[7]
            + (rightRotate(e, 6) ^ rightRotate(e, 11) ^ rightRotate(e, 25)) // S1
            + ((e & hash[5]) ^ ((~e) & hash[6])) // ch
            + k[i]
            // Expand the message schedule if needed
            + (w[i] = (i < 16) ? w[i] : (
              w[i - 16]
              + (rightRotate(w15, 7) ^ rightRotate(w15, 18) ^ (w15 >>> 3)) // s0
              + w[i - 7]
              + (rightRotate(w2, 17) ^ rightRotate(w2, 19) ^ (w2 >>> 10)) // s1
            ) | 0
            );
          // This is only used once, so *could* be moved below, but it only saves 4 bytes and makes things unreadble
          var temp2 = (rightRotate(a, 2) ^ rightRotate(a, 13) ^ rightRotate(a, 22)) // S0
            + ((a & hash[1]) ^ (a & hash[2]) ^ (hash[1] & hash[2])); // maj

          hash = [(temp1 + temp2) | 0].concat(hash); // We don't bother trimming off the extra ones, they're harmless as long as we're truncating when we do the slice()
          hash[4] = (hash[4] + temp1) | 0;
        }

        for (i = 0; i < 8; i++) {
          hash[i] = (hash[i] + oldHash[i]) | 0;
        }
      }
      var resultArr = new Array;
      for (i = 0; i < 8; i++) {
        for (j = 3; j + 1; j--) {
          var b = (hash[i] >> (j * 8)) & 255;
          resultArr.push(b);
        }
      }
      var resultAscii = '';
      for (i = 0; i < resultArr.length;i++){
        resultAscii += String.fromCharCode(resultArr[i]);
      }
      console.log(resultAscii);
      return resultAscii;
    },
    stringToBytes:function(str) {
      var ch, st, re = [];
      for (var i = 0; i < str.length; i++) {
        ch = str.charCodeAt(i);  // get char  
        st = [];                 // set up "stack"  

        do {
          st.push(ch & 0xFF);  // push byte to stack  
          ch = ch >> 8;          // shift value down by 1 byte  
        }

        while (ch);
        // add stack contents to result  
        // done because chars have "wrong" endianness  
        re = re.concat(st.reverse());
      }
      // return an array of bytes  
      return re;
}

sha256(str)


base64转二进制数组见:https://www.wikimoe.com/?post=107




donate.png

1210 x 50(蓝底).png

cloudcone