XOR operation file encryption example

Foreword:

        XOR encryption is a very simple encryption technique that is symmetric (same key for encryption and decryption), does not provide confidentiality or integrity verification and is therefore not suitable for highly sensitive data and is vulnerable to various attacks, including known Clear text attack. In practical applications, more powerful and secure encryption algorithms such as AES or RSA should be used.

effect:

Through xor calculation, the file is encrypted into an unreadable file, which cannot be repaired unless the inverse operation is used.

Perform the xor inverse operation on the encrypted code to obtain a normal readable file without any loss of the file.

fun mk_rar(assetsName: String, rarName: String) {
    val arr_b1: ByteArray
    val arr_b = ByteArray(0x1000)
    var v109: Int
    try {
        val inputStream0: InputStream = getAssets().open(assetsName)
        val byteArrayOutputStream = ByteArrayOutputStream()
        while (true) {
            v109 = inputStream0.read(arr_b)
            if (v109 <= 0) {
                break
            } else {
                byteArrayOutputStream.write(arr_b, 0, v109)
            }
        }
        arr_b1 = byteArrayOutputStream.toByteArray()
        val aar_size = arr_b1.size
        var v120 = 0
        while (v120 < aar_size) {
            arr_b1[v120] = arr_b1[v120] xor 33
            ++v120
        }
        v120 = 0
        while (v120 < aar_size / 2) {
            arr_b1[v120] = arr_b1[aar_size - 1 - v120] xor arr_b1[v120]
            ++v120
        }
        val file: File = File(getExternalFilesDir("rar"), rarName)
        val fileOutputStream = FileOutputStream(file)
        fileOutputStream.write(arr_b1)
        fileOutputStream.flush()
        fileOutputStream.close()
    } catch (e: Exception) {
    }
}

Guess you like

Origin blog.csdn.net/Steve_XiaoHai/article/details/135388564