現在、ユーザーに4桁以下の数字を入力してから暗号化し、復号化する番号をユーザーに尋ねるプログラムを作成しています。私が持っている主な問題は、どこから数学ロジックを始めるべきか分かりません。どのような提案や例をどこから始めるのが大歓迎です、ありがとうございます。C#の整数データの暗号化と復号化
-3
A
答えて
0
Javaで書かれています。私はそれがあなたに役立つと思う。
public class randStr{
private static final Random random = new SecureRandom();
//public static final int pass_length;
public static int pass_length;
public static String genRanPass()
{
//int pass_length;
Scanner scan = new Scanner(System.in);
String letters = "[email protected]#$%^&*";
String pw = "";
System.out.println("length: ");
pass_length = scan.nextInt();
try{
for(int i = 0; i<pass_length; i++){
int index = (int)(random.nextDouble()*letters.length());
pw += letters.substring(index,index+1);
}
//System.out.println(pw);
//return pw;
}
catch(Exception e){
System.out.println(e);
}
System.out.println(pw);
return pw;
}
public static void main(String args[]){
genRanPass();
//System.out.println(pw);
}
}
0
これは一つのクラスである
using System;
using System.Security.Cryptography;
public class DataProtectionSample
{
// Create byte array for additional entropy when using Protect method.
static byte[] s_aditionalEntropy = { 9, 8, 7, 6, 5 };
public static byte[] Protect(byte[] data)
{
try
{
// Encrypt the data using DataProtectionScope.CurrentUser. The result can be decrypted
// only by the same current user.
return ProtectedData.Protect(data, s_aditionalEntropy, DataProtectionScope.CurrentUser);
}
catch (CryptographicException e)
{
Console.WriteLine("Data was not encrypted. An error occurred.");
Console.WriteLine(e.ToString());
return null;
}
}
public static byte[] Unprotect(byte[] data)
{
try
{
//Decrypt the data using DataProtectionScope.CurrentUser.
return ProtectedData.Unprotect(data, s_aditionalEntropy, DataProtectionScope.CurrentUser);
}
catch (CryptographicException e)
{
Console.WriteLine("Data was not decrypted. An error occurred.");
Console.WriteLine(e.ToString());
return null;
}
}
public static void PrintValues(Byte[] myArr)
{
foreach (Byte i in myArr)
{
Console.Write("\t{0}", i);
}
Console.WriteLine();
}
}
メインクラス
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a four digit Number");
var number = Console.ReadLine();
if (!(number.Length == 4))
{
Console.WriteLine("Enter a four digit Number");
}
int i = int.Parse(number);
var bytearr = BitConverter.GetBytes(i);
method(bytearr);
Console.ReadLine();
}
public static void method(byte[] secret)
{
byte[] encryptedSecret = DataProtectionSample.Protect(secret);
Console.WriteLine("The encrypted byte array is:");
DataProtectionSample.PrintValues(encryptedSecret);
// Decrypt the data and store in a byte array.
byte[] originalData = DataProtectionSample.Unprotect(encryptedSecret);
Console.WriteLine("{0}The original data is:", Environment.NewLine);
DataProtectionSample.PrintValues(originalData);
Console.WriteLine(BitConverter.ToInt32(originalData, 0));
}
}
}
免責事項:これは単なる一例です。質問は明確ではありません。 私はこの助けを願っています。
関連する問題
- 1. C++の暗号化と復号化
- 2. C++暗号化と復号化のソースコード
- 3. シーザー暗号化と復号化C++
- 4. 暗号化と復号化
- 5. aes_cbc_128 C#ビジュアルスタジオの暗号化/復号化
- 6. C#/ Java | AES256暗号化/復号化
- 7. 暗号化C#復号化AES CBC 256
- 8. SWIFTの暗号化と復号化
- 9. ファイルの暗号化と復号化
- 10. DataTableオブジェクトの暗号化と復号化
- 11. ASP.net ViewStateの暗号化と復号化
- 12. ESAPIの暗号化と復号化
- 13. Md5ハッシュの暗号化と復号化
- 14. ファイルの復号化と暗号化
- 15. SQL Serverの暗号化と復号化
- 16. DES、RSAの暗号化と復号化
- 17. パスワードでの暗号化と復号化
- 18. 暗号化と復号化 - Javaの
- 19. pgcryptoで暗号化されたデータの復号化(C#で)
- 20. RSA暗号化/復号化
- 21. AES暗号化/復号化
- 22. 暗号化/復号化soll
- 23. 復号化、暗号化
- 24. C#とPL/SQLの暗号化と復号化の互換性
- 25. MeteorとJavaによるデータの暗号化と復号化
- 26. 暗号ブロックチェーンの復号XOR「暗号化」
- 27. C#で複数のブロックをRSA暗号化/復号化する
- 28. JavaScriptでのデータの暗号化と復号化
- 29. AESの暗号化と復号化、データの損失
- 30. PHPスイッチ:暗号化と復号化