-1
piという数字の16進表現を持つmd5ハッシュを見つけるプログラムを作成しています。私は計算を保存する上で問題があります。プログラムが文字列を正しく保存しないようです。古いものを置き換えるのではなく、長い文字列を作ります。どうすれば問題を解決できますか?あなたはFile.WriteAllText(...
を持っているし、後であなたにFile.AppendAllText(...
を持ってファイルに保存されている文字列を置き換えるにはどうすればいいですか?
public static string get_last_string()
{
string text;
string text2="";
int i= 0;
string path = "C:\\Users\\uname\\Desktop";
var fileStream = new FileStream(@path + "\\last.txt", FileMode.Open, FileAccess.Read);
using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
{
text = streamReader.ReadToEnd();
}
i=0;
while (i < text.Length && text[i] != ' ')
{
text2 += text[i];
++i;
}
return text2;
}
public static void Main(string[] args)
{
string path = @"C:\Users\Uname\Desktop\test.txt";
string a = get_last_string();
Console.WriteLine("Let us continue from the string " + a);
Console.WriteLine("Ctrl+C stops the computing and saves the results to the file last.txt");
do
{
while (!Console.KeyAvailable)
{
// Console.WriteLine("md5("+a+")="+CalculateMD5Hash(a));
if (CommonPrefix(CalculateMD5Hash(a), "314159265353") >= 11)
{
Console.WriteLine(a + " " + CalculateMD5Hash(a));
File.WriteAllText(path, a + " " + CalculateMD5Hash(a));
}
a = Next(a);
}
} while (Console.ReadKey(true).Key != ConsoleKey.Escape);
File.AppendAllText(@path + "\\last.txt", a);
}