移位数组的C ++ cypher问题 [英] C++ cypher problem with shifting an array
本文介绍了移位数组的C ++ cypher问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨我遇到一个问题用户输入一个转移号码的密码程序有问题,那么这个数字会移动一个字母数组,所以它是加密的请帮助
ps我不能使用标题
hi im having trouble with a cypher program which asks the user to input a shift number then that number shifts an alphabet array so it is encrypted please help
p.s i cant use headers
#include <iostream>
using namespace std;
int getlength(char[]);
char makecypher(int);
int main(void) {
int shift;
int length = 0;
char inputarray[256];
char array[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't','u', 'v', 'w', 'x','y', 'z' } ;
cout << " Please input a string: ";
cin.getline ( inputarray,256);
// for loop to get lower case chars
for(int i = 0; inputarray[i] != 0; i++)
{
if(inputarray[i] >= 'A' && inputarray[i] <= 'Z')
{
inputarray[i] += 32;
}
length++;
}
// removes spaces and non alphabetic chars
for(int j = 0; inputarray[j] != 0; j++)
{
if ((inputarray[j] < 97) || (inputarray[j] > 122))
{
int remove = 1;
for(int k = 0; k < length; k++)
{
inputarray[j+k] = inputarray[j+remove];
remove++;
}
j--;
}
}
cout << "You input: \n" << inputarray <<"\n";
cout << " The length of the string is: " << getlength(inputarray);
cout << "\n";
cout << " please enter the shift value: ";
cin >> shift;
cout << " the alpha : " << makecypher(shift);
cin.ignore(3);
}
int getlength(char inputarray[])
{
int charlength = 0;
while((*inputarray) != '\0')
{
charlength++;
inputarray++;
}
return charlength;
}
char makecypher( int shift )
{
char alphaarray[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't','u', 'v', 'w', 'x','y', 'z' } ;
char cipherarray[27];
int i = 0;
static int shift;
for (int z = 0; z < 26; z++) // For Loop to adjust shift value
{
// If statement condition to check whether the shift value is less than 26
if (z < 26)
{
// Then shift and replace the element in the array
cipherarray[z] = alphaarray[shift];
i++; // Increment i to get the next character in the array
}
}
}
void encrypt ()
{
}
推荐答案
static int shift;
重新定义形式参数''shift''。
redefinition of formal parameter ''shift''.
这篇关于移位数组的C ++ cypher问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文