Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Test : MonoBehaviour {
  5. public int buttonSize = 40;
  6. public int[] sqNumbers = {1,4,9,16,25,36,49,64,81,100,121,144,169};
  7. private int sqnumber;
  8. private int size;
  9. private string alphabet = "abcdefghjklmnopqrstuvwxyz ";
  10. private string Encalphabet = "abcdefghjklmnopqrstuvwxyz-";
  11. public string txt2Encrypt;
  12. public string txt2Decrypt;
  13.  
  14.  
  15. void OnGUI() {
  16.  
  17. GUI.Label (new Rect (100, 100, 120, 20), "Cryptografy 101");
  18. GUI.Label (new Rect (100, 140, 120, 20), "text to encrypt:");
  19. txt2Encrypt = GUI.TextField (new Rect (220, 140, 120, 20), txt2Encrypt);
  20. if (GUI.Button (new Rect (100, 170, 120, 20), "Encrypt")) {
  21. EncryptText(txt2Encrypt);
  22.  
  23. }
  24. GUI.Label (new Rect (100, 190, 120, 20), "text to decrypt:");
  25. txt2Decrypt = GUI.TextField (new Rect (220, 190, 120, 20), txt2Decrypt);
  26. if (GUI.Button (new Rect (100, 220, 120, 20), "Decrypt")) {
  27. DecryptText(txt2Decrypt);
  28. }
  29.  
  30. }
  31. string EncryptText(string t2e ) {
  32. string encryption = "";
  33. int Elen = t2e.Length;
  34. for (int i=0; i < sqNumbers.Length; i++){
  35. if (Elen <= sqNumbers[i]) {
  36. sqnumber = sqNumbers[i];
  37. size = i+1;
  38. break;
  39.  
  40. }
  41. }
  42. string adtxt = t2e + t2e.Substring (0,sqnumber-Elen);
  43. for (int j=0; j < size; j++){
  44. for (int k=0; k < size; k++){
  45. int p= alphabet.IndexOf(adtxt[j+k*size]);
  46. encryption+= Encalphabet[p];
  47. }
  48. }
  49. print(encryption);
  50. return encryption;
  51. }
  52.  
  53. string DecryptText(string t2e) {
  54. string decryption = "";
  55. int Elen = t2e.Length;
  56. for (int i=0; i < sqNumbers.Length; i++){
  57. if (Elen <= sqNumbers[i]) {
  58. sqnumber = sqNumbers[i];
  59. size = i+1;
  60. break;
  61.  
  62. }
  63.  
  64. }
  65. for (int j=0; j < size; j++){
  66. for (int k=0; k < size; k++){
  67. int p= Encalphabet.IndexOf(decryption[j+k*size]);
  68. decryption+= alphabet[p];
  69.  
  70. }
  71. }
  72. print(decryption);
  73. return decryption;
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement