using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int privitekey = 1234;
Random rnd = new Random(privitekey);
var PasswordTable = Enumerable.Range(0, 65536).Select(x => new { x, o = rnd.Next() })
.OrderBy(x => x.o).Select((x, i) => new { x.x, i }).ToDictionary(x => x.i, x => x.x);
var OrgnTable = PasswordTable.ToDictionary(x => x.Value, x => x.Key);
int[] nums = { 33215, 40127, 53120, 20899, 18088, 18089, 19000, 534 };
foreach (var num in nums)
{
Console.WriteLine("{0:00000} -> {1:00000}", num, PasswordTable[num]);
}
int[] encryptnums = { 4083, 1527, 34515, 35290, 6028, 7709, 63569, 15521 };
foreach (var num in encryptnums)
{
Console.WriteLine("{0:00000} <- {1:00000}", num, OrgnTable[num]);
}
}
}
uj5u.com熱心網友回復:
//首先要明白這段代碼的意思 ,顯示陣列數值對應的亂數 第二個回圈是相反的輸出
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils,Classes,StrUtils;
var
i:Integer;
OrgnTable,PasswordTable,slist:TStringList;
encryptnums:array[1..8] of integer;
nums:array[1..8] of integer;
str:string;
begin
PasswordTable:=TStringList.Create;
OrgnTable:=TStringList.Create;
slist:=TStringList.Create;
//生成數值對應的亂數
for i:=0 to 65536 do
begin
Randomize;
PasswordTable.AddObject(IntToStr(i),TObject(Random(65536)));
slist.Add(IntToStr(i)+'->'+inttostr( Integer(PasswordTable.Objects[i])));
end;
//保存到d盤
slist.SaveToFile('D:\AA.txt');
//亂數和數值互調位置
for i:=0 to PasswordTable.Count-1 do
begin
OrgnTable.AddObject(IntToStr(Integer(PasswordTable.Objects[i])),TObject(i));
end;
nums[1]:=33215;nums[2]:=40127;nums[3]:=53120;nums[4]:=20899;
nums[5]:=18088;nums[6]:=18089;nums[7]:=19000;nums[8]:=534;
encryptnums[1]:=4083;encryptnums[2]:=1527;encryptnums[3]:=34515;encryptnums[4]:=35290;
encryptnums[5]:=6028;encryptnums[6]:=7709;encryptnums[7]:=63569;encryptnums[8]:=15521;
Writeln('顯示字符對應亂數值') ;
for i:= 1 to 8 do
begin
str:=RightStr('00000'+IntToStr(Integer(nums[i])),5)+'->'+RightStr('00000'+IntToStr(Integer(PasswordTable.Objects[nums[i]])),5);
Writeln(str) ;
end;
Writeln('顯示亂數值對應字符');
for i:= 1 to 8 do
begin
Writeln(RightStr('00000'+IntToStr(Integer(encryptnums[i])),5)+'->'+RightStr('00000'+IntToStr(Integer(OrgnTable.Objects[encryptnums[i]])),5))
end;
Readln;
// int privitekey = 1234;
// Random rnd = new Random(privitekey);
// var PasswordTable = Enumerable.Range(0, 65536).Select(x => new { x, o = rnd.Next() })
// .OrderBy(x => x.o).Select((x, i) => new { x.x, i }).ToDictionary(x => x.i, x => x.x);
// var OrgnTable = PasswordTable.ToDictionary(x => x.Value, x => x.Key);
// int[] nums = { 33215, 40127, 53120, 20899, 18088, 18089, 19000, 534 };
// foreach (var num in nums)
// {
// Console.WriteLine("{0:00000} -> {1:00000}", num, PasswordTable[num]);
// }
// int[] encryptnums = { 4083, 1527, 34515, 35290, 6028, 7709, 63569, 15521 };
// foreach (var num in encryptnums)
// {
// Console.WriteLine("{0:00000} <- {1:00000}", num, OrgnTable[num]);
// }
// Console.Read();
end.
uj5u.com熱心網友回復:
佩服了
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/103125.html
標籤:語言基礎/算法/系統設計
上一篇:急急急呀,delphi中很糾結的問題呀,一個大程式中的小計算,單獨拿出來可以正確的運行結果,但是在大程式里總是一運行就提示說訪問了錯誤的地址呀
下一篇:delphi 7 使用問題
