Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class SquareCipher : MonoBehaviour {
- public string text2encrypt;
- public string inputHere = "Input text Here";
- double Squareroot;
- string outputHere = "";
- void Start ()
- {
- //Squareroot = Mathf.RoundToInt (Mathf.Sqrt (inputHere.Length));
- }
- void encryptText ()
- {
- int length = inputHere.Length;
- string tempInput = inputHere.Replace (" ","-") + inputHere.Replace (" ","-");
- Squareroot = Mathf.Sqrt (inputHere.Length);
- bool isSquare = Squareroot % 1 == 0;
- while (!isSquare){
- length++;
- Squareroot = Mathf.Sqrt(length);
- isSquare = Squareroot % 1 == 0;
- }
- string encryptedtxt = "";
- for (int i =0; i<Squareroot; i++) {
- for (int j=0; j<(int)Squareroot*(int)Squareroot; j+=(int)Squareroot) {
- encryptedtxt += tempInput.Substring (j + i, 1);
- Debug.Log (i + "," + (j + i).ToString ());
- }
- }
- outputHere = encryptedtxt;
- }
- void OnGUI ()
- {
- GUI.Label(new Rect(145,200,200,20), "Input: ");
- GUI.Label(new Rect(400,200,200,20), "Output: ");
- outputHere = GUI.TextField(new Rect(400,225,175,150), outputHere);
- inputHere = GUI.TextField(new Rect(145,225,175,150), inputHere);
- if(GUI.Button(new Rect(100,170,120,20), "Encrypt/Decrypt")){
- encryptText();
- }
- if(GUI.Button(new Rect(100,500,120,20), "Caesar Ciphering")){
- Application.LoadLevel("CaesarCipher");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement