一个没有加密的字符串str,对字符串的每个字母进行加密,加密方式是针对每个字母进行偏移。
数组a前三位已经赋值:
a[0]=1,a[1]=2,a[2]=4。当i>=3时,数组元素a[i]=a[i-1]+a[i-2]+a[i-3],。默认z之后的字母为a。
eg:
字符串abcde 加密后bdgkr
输入描述
n
1<=n<=1000
n表示有几行字符串
str
str表示未加密的字符串
输出
每组测试数据输出一行,表示字符串密文
示例:
输入:
1
ab
输出:
bd
let arr = ['abcde','fsadfasdzx','ab']
let a= [1,2,4]
function test(){
for(let i=0;i<arr.length;i++){
let item = arr[i]
let str = ''
for(let a=0;a<item.length;a++){
str+=move(a,item)
}
console.log(str);
}
}
function move(index,arr){
let num = arr[index].charCodeAt()
if(index===0){
num+=1
}else if(index===1){
num+=2
}else if(index===2){
num+=4
}else{
let codeNum = computed(0,index)
num+=codeNum
if(num>'z'.charCodeAt()){
num = 97
}
}
return String.fromCharCode(num)
}
function computed(nowIndex,index){
if(!nowIndex) {
nowIndex = 3
}
if(!a[nowIndex]){
a.push(a[nowIndex-1]+a[nowIndex-2]+a[nowIndex-3])
}
if(nowIndex<index){
nowIndex++
return computed(nowIndex,index)
}else if(nowIndex===index){
return a[nowIndex]
}
}
test()