encryption.cs

来自「This code is a cipher which takes in a p」· CS 代码 · 共 58 行

CS
58
字号
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;


namespace Encrypt
{
	/// <summary>
	/// Summary description for Encryption.
	/// </summary>
	public class Encryption  
	{
		public Encryption()
		{
		}
		
		//this method takes in two string as arguments(the message to encrypt 
		//and the key value inputted by the user and returns a string
		public string Encrypt(string msgtoencrypt, string inc)
		{		
			string temp= "";//initiate string
			
			char charnum;		//initiate chars
			char charresult;
					
			int tempint = 0;	//initiate ints
			int numint = 0;
			int valint = 0;
			
			//set val equal to inc passed into fuction.inc is converted to a
			//32 bit integer
			valint = Convert.ToInt32(inc);
			//for loop,loops while i is less than the message length						
			for(int i=0; i< msgtoencrypt.Length; i++)
			{
				//first bit in string converted to 32bit inter and set as numint
				numint = Convert.ToInt32( msgtoencrypt[i]);
				//this then converted to a char and set as numint
				charnum = Convert.ToChar(numint);
				//tempint then set to charnum + valint
				tempint = charnum + valint;
				//this then converted to a char and set as charresult
				charresult = Convert.ToChar(tempint);
				//this then converted to a string so it can be passed back
				temp = temp + charresult.ToString();
			}
			return temp;//returns the temp value

		}


		
	}
}

⌨️ 快捷键说明

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