結果

問題 No.8005 天使のハッシュ関数
ユーザー ecottea
提出日時 2022-10-04 01:14:25
言語 C#
(.NET 8.0.404)
結果
AC  
実行時間 58 ms / 5,000 ms
コード長 1,365 bytes
コンパイル時間 19,312 ms
コンパイル使用メモリ 171,372 KB
実行使用メモリ 187,284 KB
最終ジャッジ日時 2024-12-28 07:35:29
合計ジャッジ時間 9,124 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (117 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
/home/judge/data/code/Main.cs(17,22): warning SYSLIB0021: 'MD5CryptoServiceProvider' は旧形式です ('Derived cryptographic types are obsolete. Use the Create method on the base type instead.') (https://aka.ms/dotnet-warnings/SYSLIB0021) [/home/judge/data/code/main.csproj]
/home/judge/data/code/Main.cs(33,23): warning SYSLIB0021: 'MD5CryptoServiceProvider' は旧形式です ('Derived cryptographic types are obsolete. Use the Create method on the base type instead.') (https://aka.ms/dotnet-warnings/SYSLIB0021) [/home/judge/data/code/main.csproj]
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

// https://atmarkit.itmedia.co.jp/fdotnet/dotnettips/964computehash/computehash.html

using System;
using System.Security.Cryptography;
using System.Text;

class Program
{
  static void Main()
  {
    string originalText = Console.ReadLine();

    // テキストをUTF-8エンコードでバイト配列化
    byte[] byteValue = Encoding.UTF8.GetBytes(originalText);

    // MD5のハッシュ値を取得する
    MD5 crypto = new MD5CryptoServiceProvider();
    byte[] hashValue = crypto.ComputeHash(byteValue);

    // バイト配列をUTF8エンコードで文字列化
    StringBuilder hashedText = new StringBuilder();
    for (int i = 0; i < hashValue.Length; i++)
    {
      hashedText.AppendFormat("{0:x2}", hashValue[i]);
    }
    
    string originalText2 = hashedText.ToString();
    
    // テキストをUTF-8エンコードでバイト配列化
    byte[] byteValue2 = Encoding.UTF8.GetBytes(originalText2);

    // MD5のハッシュ値を取得する
    MD5 crypto2 = new MD5CryptoServiceProvider();
    byte[] hashValue2 = crypto.ComputeHash(byteValue2);

    // バイト配列をUTF8エンコードで文字列化
    StringBuilder hashedText2 = new StringBuilder();
    for (int i = 0; i < hashValue2.Length; i++)
    {
      hashedText2.AppendFormat("{0:x2}", hashValue2[i]);
    }
    Console.WriteLine(hashedText2.ToString());
  }
}
0