帮忙看个入门的加密问题
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using
namespace 加密程序
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string Encrypt(string s)
{
Encoding ascii = Encoding.Default;
string EncryptString;
EncryptString = "";
for (int i = 0; i<s.Length; i++)
{
int j;
byte[] b = new byte[1];
j = Convert.ToInt32(ascii.GetBytes(s[i].ToString())[0]);
j += 1;
b[0] = Convert.ToByte(j);
EncryptString = EncryptString + ascii.GetString(b);
}
return EncryptString;
}
private string Decryptor(string s) {
Encoding ascii = Encoding.Default;
string DecrytorString;
DecrytorString = "";
for (int i = 0; i < s.Length; i++) {
int j;
byte[] b = new byte[1];
j = Convert.ToInt32(ascii.GetBytes(s[i].ToString())[0]);
j = j - 1;
b[0]=Convert.ToByte(j);
DecrytorString = DecrytorString + ascii.GetString(b);
}
return DecrytorString;
}
private void button2_Click(object sender, EventArgs e)
{
richTextBox1.Text = Encrypt(richTextBox1.Text);
}
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.Clear();
this.openFileDialog1.ShowDialog();
StreamReader sr = new StreamReader(openFileDialog1.FileName, Encoding.Default);
richTextBox1.Text = sr.ReadToEnd();
sr.Close();
}
private void button3_Click(object sender, EventArgs e)
{
richTextBox1.Text = Decryptor(richTextBox1.Text);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
第一个问题 这个加密程序貌似不能加密中文的
第二个问题 红字+部分可以换成s[i]吗 msdn上encoding。getByte()重载方法里有字符型的 但是我换成S[i]编译就报错
只有10分了 不好意思