I do a Mini Program to calculate the temporary password. According to everyone"s help, the following code is written. After running, the form can be displayed, but there is an error:
app.js code is as follows:
const app = getApp()
const mSecDataTempPd = 0x5aa555aa;
const coSecDataTempPd = mSecDataTempPd ^ 0x9e3779b9 & 0xffffffff;
const KEY = [0x126f2e1b, 0xd1ef3da9, 0xa7469115, 0x6d83ea82];
const PERIOD_CYCLE = 15 * 60;
var p = new Uint8Array([0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff])
Page({
onLaunch: function getTempPasswd(passwd, time) {
var bytes = new Uint32Array(2);
var byteView = new Uint8Array(bytes.buffer);
var periodCount = Math.floor(time.valueOf() / 1000 / PERIOD_CYCLE);
for (var i = 0; i < 8; iPP) {
if (i < 6) {
byteView[i] = ((passwd[i * 2] << 4) & 0xf0) | (passwd[i * 2 + 1] & 0x0f);
} else {
byteView[i] = 0;
}
if (i > 3) {
byteView[i] ^= periodCount >> ((7 - i) * 8);
}
}
encryptTEA(bytes);
var dataToReturn = new Uint8Array(8);
for (var i = 0; i < 8; iPP) {
dataToReturn[i] = (((byteView[i] >> 4) & 0x0f) ^ (byteView[i] & 0x0f)) % 10;
}
return dataToReturn;
},
onLaunch: function encryptTEA(bytes) {
var t1 = bytes[0];
var t2 = bytes[1];
var sum = 0;
var delta = coSecDataTempPd ^ mSecDataTempPd & 0xffffffff;
for (var i = 0; i < 8; iPP) {
sum = (sum + delta) & 0xffffffff;
t1 += ((t2 << 4) + KEY[0]) ^ (t2 + sum) ^ ((t2 >> 5) + KEY[1]);
t1 &= 0xffffffff;
t2 += ((t1 << 4) + KEY[2]) ^ (t1 + sum) ^ ((t1 >> 5) + KEY[3]);
t2 &= 0xffffffff;
}
bytes[0] = t1;
bytes[1] = t2;
}
})
the app.json code is as follows:
{
"pages":[
"pages/index/index",
"pages/guanyu/index"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "-sharpeee",
"navigationBarTitleText": "",
"navigationBarTextStyle":"black"
},
"tabBar": {
"color": "-sharp000000",
"borderStyle": "-sharp000",
"selectedColor": "-sharp9999FF",
"list": [
{
"pagePath": "pages/index/index",
"text": "",
"iconPath": "images/home-off.png",
"selectedIconPath": "images/home-on.png"
},
{
"pagePath": "pages/guanyu/index",
"text": "",
"iconPath": "images/tab_search_def@2x.png",
"selectedIconPath": "images/tab_search_sel@2x.png"
}
]
}
}
the index.wxml code is as follows:
<view class="btn-area">
<text class="biaoti">:\n</text>
<text class="neirong">:\n</text>
<text class="neirong">00001459\n</text>
<text class="neirong">15002959\n</text>
<text class="neirong">30004459\n</text>
<text class="neirong">45005959\n</text>
<text>\n</text>
<input type="number" maxlength="12" />
<button bindtap="getTempPasswd(p, new Date())"></button>
<view class="section">
<input value="{{p}}" />
</view>
</view>
shows the following mobile interface:
:
would you please help me to see what the mistake is? And can you help me improve it? my purpose is to use the calculation function to calculate the password entered by the user in the first INPUT, through the calculation function to calculate the temporary password and then display it in the second INPUT.