Advertisement
Guest User

Untitled

a guest
Mar 1st, 2019
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. public class UserInfo
  2. {
  3. private String name, userAddress, username, password;
  4. public UserInfo()
  5. {
  6. name = "";
  7. userAddress = "";
  8. username = "";
  9. password = "";
  10. }
  11.  
  12. public void setName(String name)
  13. {
  14. this.name = name;
  15. }
  16. public String getName()
  17. {
  18. return name;
  19. }
  20. public void setUserAddress(String userAddress)
  21. {
  22. this.userAddress = userAddress;
  23. }
  24. public String getUserAddress()
  25. {
  26. return userAddress;
  27. }
  28. public void setUsername(String username)
  29. {
  30. this.username = username;
  31. }
  32. public String getUsername()
  33. {
  34. return username;
  35. }
  36. public void setPassword(String password)
  37. {
  38. this.password = this.encrypt(password);
  39. }
  40. public String toString()
  41. {
  42. String result;
  43. result = "User's name: " + name + "\n";
  44. result += "User's address: " + userAddress + "\n";
  45. result += "User's desired username : " + username + "\n";
  46. return result;
  47. }
  48. public String encrypt (String s)
  49. {
  50. s = removeWhitespaceAndConvertToUpper(s);
  51. s = substitute(s);
  52. s = swapHalfsForEncrypt(s);
  53. s = swapFirst2WithLast2(s);
  54. s = swapMiddleChars(s);
  55. return s;
  56. }
  57.  
  58. public String removeWhitespaceAndConvertToUpper(String a)
  59. {
  60. a.trim();
  61. a.toUpperCase();
  62. return a;
  63. }
  64. public String substitute (String a)
  65. {
  66. a.replace('A', '@');
  67. a.replace('E', '=');
  68. a.replace('I', '!');
  69. a.replace('J', '?');
  70. a.replace('O', '*');
  71. a.replace('P', '#');
  72. a.replace('R', '&');
  73. a.replace('S', '$');
  74. a.replace('T', '+');
  75. a.replace('V', '^');
  76. a.replace('X', '%');
  77. a.replace(' ', '_');
  78. return a;
  79. }
  80. public String swapHalfsForEncrypt(String a)
  81. {
  82. int lengthFirstHalf = (int)Math.ceil(a.length()/2.0);
  83. int lengthSecondHalf = a.length() - lengthFirstHalf;
  84. String firstHalf = a.substring(0, lengthFirstHalf);
  85. String secondHalf = a.substring(lengthFirstHalf, a.length());
  86. return secondHalf + firstHalf;
  87. }
  88. public String swapFirst2WithLast2 (String a)
  89. {
  90. String first2Char = a.substring(0, 2);
  91. String last2Char = a.substring(a.length() -2);
  92. String middle = a.substring(2, a.length() -2);
  93. return last2Char + middle + first2Char;
  94. }
  95. public String swapMiddleChars (String a)
  96. {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement