Advertisement
Guest User

Untitled

a guest
Mar 1st, 2019
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. public class UserInfo {
  2. private String name, address, username, password;
  3.  
  4. public UserInfo() {
  5. name = "";
  6. address = "";
  7. username = "";
  8. password = "";
  9. }
  10.  
  11. public void setName(String name) {
  12. this.name = name;
  13. }
  14.  
  15. public String getName() {
  16. return name;
  17. }
  18.  
  19. public void setAddress(String address) {
  20. this.address = address;
  21. }
  22.  
  23. public String getAddress() {
  24. return address;
  25. }
  26.  
  27. public void setUsername(String username) {
  28. this.username = username;
  29. }
  30.  
  31. public String getUsername() {
  32. return username;
  33. }
  34.  
  35. public void setPassword(String password) {
  36. this.password = password;
  37. }
  38.  
  39. public String getPassword() {
  40. return password;
  41. }
  42.  
  43. public String encrypt(String s) { // encrypt method -- applying all other encryption methods to String s
  44. s = removeWhitespaceAndConvertToUpper(s);
  45. s = substitute(s);
  46. s = swapHalfsForEncrypt(s);
  47. s = swapFirst2WithLast2(s);
  48. s = swapMiddleChars(s);
  49. return s;
  50. }
  51.  
  52. public String removeWhitespaceAndConvertToUpper(String s) {
  53. String trimmedStr = "";
  54. trimmedStr = s.trim(); // removes leading and trailing whitespace for String s
  55. return trimmedStr.toUpperCase(); // converts all letters in String to uppercase
  56. }
  57.  
  58. public String substitute(String s) { // performs all listed ASCII character substitutions
  59. s = s.replace('A', '@');
  60. s = s.replace('E', '=');
  61. s = s.replace('I', '!');
  62. s = s.replace('J', '?');
  63. s = s.replace('O', '*');
  64. s = s.replace('P', '#');
  65. s = s.replace('R', '&');
  66. s = s.replace('S', '$');
  67. s = s.replace('T', '+');
  68. s = s.replace('V', '^');
  69. s = s.replace('X', '%');
  70. s = s.replace(' ', '_');
  71. return s;
  72. }
  73.  
  74. public String swapHalfsForEncrypt(String s) {
  75. String swappedStr = s.substring(s.length() / 2, s.length()); // sets swappedStr to be second half of s
  76. swappedStr += s.substring(0, s.length() / 2); // concatenates swappedStr to first half of s, switching halves
  77. return swappedStr;
  78. }
  79.  
  80. public String swapFirst2WithLast2(String s) {
  81. String swappedStr = s.substring(s.length() - 2); // sets swappedStr to be last two chars
  82. swappedStr += s.substring(2, s.length() - 2); // concatenates swappedStr with middle block of String
  83. swappedStr += s.substring(0, 2); // concatenates swappedStr to first two chars, switching first and last 2
  84. return swappedStr;
  85. }
  86.  
  87. public String swapMiddleChars(String s) {
  88. String swappedStr = s.substring(0, (
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement