Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class UserInfo {
- private String name, address, username, password;
- public UserInfo() {
- name = "";
- address = "";
- username = "";
- password = "";
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getName() {
- return name;
- }
- public void setAddress(String address) {
- this.address = address;
- }
- public String getAddress() {
- return address;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getUsername() {
- return username;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public String getPassword() {
- return password;
- }
- public String encrypt(String s) { // encrypt method -- applying all other encryption methods to String s
- s = removeWhitespaceAndConvertToUpper(s);
- s = substitute(s);
- s = swapHalfsForEncrypt(s);
- s = swapFirst2WithLast2(s);
- s = swapMiddleChars(s);
- return s;
- }
- public String removeWhitespaceAndConvertToUpper(String s) {
- String trimmedStr = "";
- trimmedStr = s.trim(); // removes leading and trailing whitespace for String s
- return trimmedStr.toUpperCase(); // converts all letters in String to uppercase
- }
- public String substitute(String s) { // performs all listed ASCII character substitutions
- s = s.replace('A', '@');
- s = s.replace('E', '=');
- s = s.replace('I', '!');
- s = s.replace('J', '?');
- s = s.replace('O', '*');
- s = s.replace('P', '#');
- s = s.replace('R', '&');
- s = s.replace('S', '$');
- s = s.replace('T', '+');
- s = s.replace('V', '^');
- s = s.replace('X', '%');
- s = s.replace(' ', '_');
- return s;
- }
- public String swapHalfsForEncrypt(String s) {
- String swappedStr = s.substring(s.length() / 2, s.length()); // sets swappedStr to be second half of s
- swappedStr += s.substring(0, s.length() / 2); // concatenates swappedStr to first half of s, switching halves
- return swappedStr;
- }
- public String swapFirst2WithLast2(String s) {
- String swappedStr = s.substring(s.length() - 2); // sets swappedStr to be last two chars
- swappedStr += s.substring(2, s.length() - 2); // concatenates swappedStr with middle block of String
- swappedStr += s.substring(0, 2); // concatenates swappedStr to first two chars, switching first and last 2
- return swappedStr;
- }
- public String swapMiddleChars(String s) {
- String swappedStr = s.substring(0, (
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement