Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    private static String key2 = "Aedse_!#@..";
    private static String key1 = "13245";

    public static String encryptionKey(String password) {
        byte[] keyByte1 = key1.getBytes();
        byte[] keyByte2 = key2.getBytes();
        byte[] pwdByte = password.getBytes();
        for (int i = 0; i < pwdByte.length; i++) {
            pwdByte[i] = (byte) (pwdByte[i] ^ keyByte1[i % keyByte1.length]);
        }
        byte[] countByte = new byte[pwdByte.length + keyByte1.length];
        for (int i = 0; i < countByte.length; i++) {
            if (i < pwdByte.length)
                countByte[i] = pwdByte[i];
            else
                countByte[i] = keyByte1[i - pwdByte.length];
        }
        for (int i = 0; i < countByte.length; i++) {
            countByte[i] = (byte) (countByte[i] ^ keyByte2[i % keyByte2.length]);
        }
        return bytesToHexString(countByte);
    }

    public static final String bytesToHexString(byte[] bArray) {
        StringBuffer sb = new StringBuffer(bArray.length);
        String sTemp;
        for (int i = 0; i < bArray.length; i++) {
            sTemp = Integer.toHexString(0xFF & bArray[i]);
            if (sTemp.length() < 2)
                sb.append(0);
            sb.append(sTemp.toUpperCase());
        }
        return sb.toString();
    }
}