viginear.cs

来自「使用viginear,column permutation,DES加密和解密」· CS 代码 · 共 45 行

CS
45
字号
using System;
using System.Collections.Generic;
using System.Text;

namespace MyCAP
{
    class viginear
    {
        public string GetCipher(string plain, string key)
        {
            int i, j = 0;// i for  circle , j for remember the position of char in key
            int tem;//for remembering the cipher number
            string cipher = null;
            for (i = 0; i < plain.Length; i++)
            {
                if (j == key.Length)
                    j = 0;
                tem = (int)plain[i] + (int)key[j++] - (int)'a';
                if (tem > 'z')
                    tem = tem - 26;
                cipher += (char)tem;
            }
            return cipher;
        }

        public string Getplain(string cipher, string key)
        {
            int i, j = 0;// i for  circle , j for remember the position of char in key
            int tem;//for remembering the cipher number
            string plain = null;
            for (i = 0; i < cipher.Length; i++)
            {
                if (j == key.Length)
                    j = 0;
                tem = (int)cipher[i] - (int)key[j++] + (int)'a';
                if (tem < 'a')
                    tem = tem + 26;
                plain += (char)tem;
            }
            return plain;
        }

    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?