Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class SquareCipher : MonoBehaviour {
  5. public string text2encrypt;
  6. public string inputHere = "Input text Here";
  7. double Squareroot;
  8. string outputHere = "";
  9.  
  10. void Start ()
  11. {
  12. //Squareroot = Mathf.RoundToInt (Mathf.Sqrt (inputHere.Length));
  13. }
  14.  
  15. void encryptText ()
  16. {
  17. int length = inputHere.Length;
  18. string tempInput = inputHere.Replace (" ","-") + inputHere.Replace (" ","-");
  19. Squareroot = Mathf.Sqrt (inputHere.Length);
  20. bool isSquare = Squareroot % 1 == 0;
  21. while (!isSquare){
  22. length++;
  23. Squareroot = Mathf.Sqrt(length);
  24. isSquare = Squareroot % 1 == 0;
  25. }
  26. string encryptedtxt = "";
  27. for (int i =0; i<Squareroot; i++) {
  28. for (int j=0; j<(int)Squareroot*(int)Squareroot; j+=(int)Squareroot) {
  29. encryptedtxt += tempInput.Substring (j + i, 1);
  30. Debug.Log (i + "," + (j + i).ToString ());
  31. }
  32. }
  33. outputHere = encryptedtxt;
  34. }
  35.  
  36. void OnGUI ()
  37. {
  38. GUI.Label(new Rect(145,200,200,20), "Input: ");
  39. GUI.Label(new Rect(400,200,200,20), "Output: ");
  40. outputHere = GUI.TextField(new Rect(400,225,175,150), outputHere);
  41. inputHere = GUI.TextField(new Rect(145,225,175,150), inputHere);
  42. if(GUI.Button(new Rect(100,170,120,20), "Encrypt/Decrypt")){
  43. encryptText();
  44. }
  45. if(GUI.Button(new Rect(100,500,120,20), "Caesar Ciphering")){
  46. Application.LoadLevel("CaesarCipher");
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement