【C#】26. Enigma 模拟器

昨天和一个朋友又看了一遍模拟游戏,晚上回到家里闲的无聊,就写了一个简单的enigma模拟器。主要熟悉了他的加密算法以及解密设置。总的来说并不复杂,今天早上还做了一下UI,虽然没有做反射器,但是觉得基本上也是一个挺好玩的东西了,所以贴出来~




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;

namespace ENIGMA
{
    public class EnigmaSystem
    {
        //定义转子
        public int[,] rotatorsPos;
        public int[,] currentPos;
        public Dictionary<char, int> input;
        public Dictionary<int, char> output;
        
        //构造器
        public EnigmaSystem()
        {
        }

        //初始化转子
        public void Load(string path)
        {
            //初始化绑定输入输出字典
            #region 初始化绑定
            input =new Dictionary<char,int>(26);
            for (int i= 65; i<=90; i++)
            {
                input.Add((char)i, i-64);
            }

            output = new Dictionary<int, char>(26);
            for (int i = 65; i <= 90; i++)
            {
                output.Add( i - 64,(char)i);
            }
            #endregion

            //初始化转子
            rotatorsPos = new int [3,26]; //3*26
            currentPos = new int [3, 26];

            //从外部txt读入rotators固化线路的位置信息矩阵
            TxtToRotators(path);
        }

        //设置转子
        public void Setting(int rotator1=0, int rotator2=0, int rotator3=0)
        {
            int setting = rotator1 + 26 * rotator2 + 26 * 26 * rotator3;
            currentPos = TurningRotator(setting);
        }
        //将Rotators数据写入到txt文件中
        public void RotatorsToTxt(string path ="D:\\RotatorsData.txt" )
        {
            StreamWriter sw = new StreamWriter(path);
            for (int i = 0; i < rotatorsPos.GetLength(0); i++)
            {
                for (int j = 1; j <= rotatorsPos.GetLength(1); j++)
                {
                    sw.Write(rotatorsPos[i, j]);
                    sw.Write(' ');
      
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值