32 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			32 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
import java.util.Base64;
 | 
						|
 | 
						|
public class Blowfish implements Cryptable {
 | 
						|
    private static final String SECRET_KEY = "MySecretKey";  // Simple key for XOR
 | 
						|
 | 
						|
    @Override
 | 
						|
    public String encrypt(String data) {
 | 
						|
        byte[] dataBytes = data.getBytes();
 | 
						|
        byte[] encryptedData = new byte[dataBytes.length];
 | 
						|
 | 
						|
        // XOR encryption
 | 
						|
        for (int i = 0; i < dataBytes.length; i++) {
 | 
						|
            encryptedData[i] = (byte) (dataBytes[i] ^ SECRET_KEY.charAt(i % SECRET_KEY.length()));
 | 
						|
        }
 | 
						|
 | 
						|
        return Base64.getEncoder().encodeToString(encryptedData);
 | 
						|
    }
 | 
						|
 | 
						|
    @Override
 | 
						|
    public String decrypt(String cryptedData) {
 | 
						|
        byte[] encryptedData = Base64.getDecoder().decode(cryptedData);
 | 
						|
        byte[] decryptedData = new byte[encryptedData.length];
 | 
						|
 | 
						|
        // XOR decryption (same as encryption)
 | 
						|
        for (int i = 0; i < encryptedData.length; i++) {
 | 
						|
            decryptedData[i] = (byte) (encryptedData[i] ^ SECRET_KEY.charAt(i % SECRET_KEY.length()));
 | 
						|
        }
 | 
						|
 | 
						|
        return new String(decryptedData);
 | 
						|
    }
 | 
						|
}
 |