一道练习题,好像很简单,搞不定了,郁闷……

我是丁学 2006-04-18 06:30:12
写一段字符串加密的程序,加密方式为:
密文第一个字符是原文的最后一个字符,其余每个字符为原文的前一个字符的值加2。
比如:原字符串为 dxef ,则加密后第一个字符为 f ,其余的 dxe 中字符值分别加2为 fzg
连起来,则密文为 ffzg
...全文
200 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
伴老思源 2006-04-18
  • 打赏
  • 举报
回复
using System;
public string strHash(string strValue)
{
byte[] arrIn = Encoding.Default.GetBytes(strValue);
byte[] arrOut= Encoding.Default.GetBytes(strValue);
string strReturn="";
arrOut[0] = (byte)arrIn .GetValue(arrIn.Length-1);
for(int i=0;i<arrIn.Length-1;i++)
{
int nCount = Convert.ToInt32(arrIn.GetValue(i))+2;
if( ( nCount > 90 && nCount < 99 )||( nCount > 122 ) )
{
nCount -= 26;
}
arrOut[i+1] = (byte)((char)nCount);
strReturn = System.Text.Encoding.Default.GetString(arrayOut);
}
return strReturn;
}
-渔民- 2006-04-18
  • 打赏
  • 举报
回复
學習啦
webwait 2006-04-18
  • 打赏
  • 举报
回复
public string strEncoding(string vstrIn)
{

byte[] arrayIn= System.Text.Encoding.Default.GetBytes(vstrIn);
byte[] arrayOut= System.Text.Encoding.Default.GetBytes(vstrIn);
string strReturn="";
int tmp;
arrayOut[0]=(byte)arrayIn.GetValue(arrayIn.Length-1);

for(int i=0;i<arrayIn.Length-1;i++)
{
tmp=Convert.ToInt32(arrayIn.GetValue(i))+2;

if((tmp>90&&tmp<99)||(tmp>122))
{
tmp-=26;
}
arrayOut[i+1]=(byte)((char)tmp);
strReturn=System.Text.Encoding.Default.GetString(arrayOut);

}
return strReturn;


}
  • 打赏
  • 举报
回复
using System;
namespace test
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string strin,strout;
char temp;
strin = Console.ReadLine();
int i;
strout="";
for (i=0;i<strin.Length;i++)
{
temp=strin[i];
if (i==strin.Length-1)
{
strout=temp+strout;
}
else
{
strout=strout+Convert.ToChar(Convert.ToInt32(temp)+2);
}
}

Console.WriteLine(strout);
Console.ReadLine();
}
}
}
我是丁学 2006-04-18
  • 打赏
  • 举报
回复
收到,结帐

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧