Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Test : MonoBehaviour {
- public int buttonSize = 40;
- public int[] sqNumbers = {1,4,9,16,25,36,49,64,81,100,121,144,169};
- private int sqnumber;
- private int size;
- private string alphabet = "abcdefghjklmnopqrstuvwxyz ";
- private string Encalphabet = "abcdefghjklmnopqrstuvwxyz-";
- public string txt2Encrypt;
- public string txt2Decrypt;
- void OnGUI() {
- GUI.Label (new Rect (100, 100, 120, 20), "Cryptografy 101");
- GUI.Label (new Rect (100, 140, 120, 20), "text to encrypt:");
- txt2Encrypt = GUI.TextField (new Rect (220, 140, 120, 20), txt2Encrypt);
- if (GUI.Button (new Rect (100, 170, 120, 20), "Encrypt")) {
- EncryptText(txt2Encrypt);
- }
- GUI.Label (new Rect (100, 190, 120, 20), "text to decrypt:");
- txt2Decrypt = GUI.TextField (new Rect (220, 190, 120, 20), txt2Decrypt);
- if (GUI.Button (new Rect (100, 220, 120, 20), "Decrypt")) {
- DecryptText(txt2Decrypt);
- }
- }
- string EncryptText(string t2e ) {
- string encryption = "";
- int Elen = t2e.Length;
- for (int i=0; i < sqNumbers.Length; i++){
- if (Elen <= sqNumbers[i]) {
- sqnumber = sqNumbers[i];
- size = i+1;
- break;
- }
- }
- string adtxt = t2e + t2e.Substring (0,sqnumber-Elen);
- for (int j=0; j < size; j++){
- for (int k=0; k < size; k++){
- int p= alphabet.IndexOf(adtxt[j+k*size]);
- encryption+= Encalphabet[p];
- }
- }
- print(encryption);
- return encryption;
- }
- string DecryptText(string t2e) {
- string decryption = "";
- int Elen = t2e.Length;
- for (int i=0; i < sqNumbers.Length; i++){
- if (Elen <= sqNumbers[i]) {
- sqnumber = sqNumbers[i];
- size = i+1;
- break;
- }
- }
- for (int j=0; j < size; j++){
- for (int k=0; k < size; k++){
- int p= Encalphabet.IndexOf(decryption[j+k*size]);
- decryption+= alphabet[p];
- }
- }
- print(decryption);
- return decryption;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement