字符显示为 'y' 而不是 space '
character shows up as 'y' instead of a space '
在 matlab 中,我正在编写 Ceaser Cipher,但 space 显示为 'y' 字符。
我如何用 space
替换它
case 4
disp('Breaking Ceaser Cipher')
cs = menu('Please Enter your Choice','Encryption','Decryption');
if cs==1
c = input('Enter the message: ','s');
sh = str2double(input('Enter shift: ','s'));
c=upper(c);
lc=length(c);
for i=1:lc
p(i)=int16(c(i))-65+sh;
end
p=mod(p,26)+97;
p=char(p);
disp( p)
end
end
输出示例:
Breaking Ceaser Cipher
Enter the message:
my name is jeff
Enter shift:
5
rdysfrjynxyojkk
这里我们看到加密是正确的,但是 space 被 'y' 替换了。当用作输入时,它不会替换字符 'y',space 栏以某种方式显示为 'y'。
我也尝试过使用 p2 = regexprep(c, 'y', ' ')
来用 space.Also 替换 'y' 字符串,研究了 isspace 函数。运气不好
你已经完成一半了:
spaces=isspace(c)
% make array of spaces
out=blanks(size(c));
% get array without spaces
c=c(~spaces);
% do stuff to c, without spaces.
p=mod(p,26)+97;
p=char(p);
% Fill p in corresponding locations
out(~spaces)=p;
在 matlab 中,我正在编写 Ceaser Cipher,但 space 显示为 'y' 字符。 我如何用 space
替换它 case 4
disp('Breaking Ceaser Cipher')
cs = menu('Please Enter your Choice','Encryption','Decryption');
if cs==1
c = input('Enter the message: ','s');
sh = str2double(input('Enter shift: ','s'));
c=upper(c);
lc=length(c);
for i=1:lc
p(i)=int16(c(i))-65+sh;
end
p=mod(p,26)+97;
p=char(p);
disp( p)
end
end
输出示例:
Breaking Ceaser Cipher
Enter the message:
my name is jeff
Enter shift:
5
rdysfrjynxyojkk
这里我们看到加密是正确的,但是 space 被 'y' 替换了。当用作输入时,它不会替换字符 'y',space 栏以某种方式显示为 'y'。
我也尝试过使用 p2 = regexprep(c, 'y', ' ')
来用 space.Also 替换 'y' 字符串,研究了 isspace 函数。运气不好
你已经完成一半了:
spaces=isspace(c)
% make array of spaces
out=blanks(size(c));
% get array without spaces
c=c(~spaces);
% do stuff to c, without spaces.
p=mod(p,26)+97;
p=char(p);
% Fill p in corresponding locations
out(~spaces)=p;