Cypher

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 347defb65e1ad461983e0f3c87b6a6543ecd7133
parent 440210c12db9138dcad2db9d1833fbd5082dc0a6
Author: Minerva_juppiter <94231606+minerva-jupiter@users.noreply.github.com>
Date:   Wed, 20 Apr 2022 22:40:55 +0900

プロジェクト ファイルを追加します。

Diffstat:
ACypher.csproj | 10++++++++++
ACypher.sln | 25+++++++++++++++++++++++++
AProgram.cs | 135+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 170 insertions(+), 0 deletions(-)

diff --git a/Cypher.csproj b/Cypher.csproj @@ -0,0 +1,10 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net6.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + +</Project> diff --git a/Cypher.sln b/Cypher.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.32407.343 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cypher", "Cypher.csproj", "{BA629338-C60A-4C00-95D7-7A6E7AE4A721}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BA629338-C60A-4C00-95D7-7A6E7AE4A721}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BA629338-C60A-4C00-95D7-7A6E7AE4A721}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BA629338-C60A-4C00-95D7-7A6E7AE4A721}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BA629338-C60A-4C00-95D7-7A6E7AE4A721}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D21ACD2D-F5BD-4268-A5FE-5E790E38C9C5} + EndGlobalSection +EndGlobal diff --git a/Program.cs b/Program.cs @@ -0,0 +1,134 @@ +using System.Text; +using System; +using System.IO; + +static void main(string[] args) +{ + +} +void sort() +{ + //復号プログラム + + //変数宣言 + int[] order = new int[100]; + string written; + int a = 0; + int b = 0; + + //順序ファイルの読み込み + StreamReader sr = new StreamReader(path: "D:\a.txt", encoding: Encoding.GetEncoding("UTF-8")); + Console.WriteLine("読み込み終わり"); + + //配列に順序を書き込み + while (a < 100) + { + order[a] = int.Parse(sr.ReadLine()); + a++; + } + + //配列の順に検索 + a = 0; + StreamWriter writer = new StreamWriter("after.txt", true); + while (a < 100) + { + //参照すべき行を検索 + b = Array.IndexOf(order, a); + + //参照して"written"に代入 + written = File.ReadLines(@"D:\date.txt").Skip(b).First(); + + //"after"に書き込み + Encoding sjisEnc = Encoding.GetEncoding("UTF-8"); + writer.WriteLine(written); + + } + writer.Close(); +} + +void testCreate() +{ + int a = 0; + int[] order; + while (a < 100) + { + StreamWriter streamWriter = new StreamWriter(@"D:\a.txt", false, Encoding.GetEncoding("UTF-16")); + streamWriter.WriteLine(a); + Console.WriteLine(a + "を書き込んでいます。"); + a++; + } +} + +void createOrder() +{ + //順序ファイルの生成 + int random; + int a = 0; + int[] order = new int[100]; + //百個数字が埋められるまで繰り返す。 + while (a >= 100) + { + //Int32と同じサイズのバイト配列にランダムな値を設定する + //byte[] bs = new byte[sizeof(int)]; + byte[] bs = new byte[4]; + System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider(); + rng.GetBytes(bs); + //.NET Framework 4.0以降 + rng.Dispose(); + + //Int32に変換する + random = System.BitConverter.ToInt32(bs, 0); + //現在時刻を取得 + //this.dateTime = DateTime.Now; + //下二桁を抽出 + random = random % 100; + //書き出し + Console.WriteLine(random); + + //生成した変数を"order"に代入 + order[a] = random; + + //if (Array.IndexOf(order, random) >= 0) + //{ + //生成した変数を"order"に代入 + //order[a] = random; + //a++; + + } +} + +void encrypt() +{ + //変数宣言 + int[] order = new int[100]; + string written; + int a = 0; + int b = 0; + + //順序ファイルの読み込み + StreamReader sr = new StreamReader(path: "D:\a.txt", encoding: Encoding.GetEncoding("UTF-8")); + Console.WriteLine("読み込み終わり"); + + //配列に順序を書き込み + while (a < 100) + { + order[a] = int.Parse(sr.ReadLine()); + a++; + } + //配列の順に検索 + a = 0; + while (a < 100) + { + //参照すべき行を検索 + b = Array.IndexOf(order, a); + + //参照して"written"に代入 + written = File.ReadLines(@"D:\after.txt").Skip(b).First(); + + //"encrypted"に書き込み + StreamWriter writer = new StreamWriter("encrypted.txt", true); + writer.WriteLine(written); + + } + writer.Close(); +}+ \ No newline at end of file