Java String Descrypt decrypt(byte[] ciphertextBytes, int r, int n)

Here you can find the source of decrypt(byte[] ciphertextBytes, int r, int n)

Description

decrypt

License

Apache License

Declaration

private static byte[] decrypt(byte[] ciphertextBytes, int r, int n) 

Method Source Code

//package com.java2s;
/*/*from www  .j a v  a  2s . c o  m*/
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    private static byte[] decrypt(byte[] ciphertextBytes, int r, int n) {
        byte[] buffer = new byte[ciphertextBytes.length];

        int c1 = 52845;
        int c2 = 22719;

        for (int i = 0; i < ciphertextBytes.length; i++) {
            int cipher = ciphertextBytes[i] & 0xff;
            int plain = cipher ^ r >> 8;

            buffer[i] = (byte) plain;

            r = (cipher + r) * c1 + c2 & 0xffff;
        }

        byte[] plaintextBytes = new byte[ciphertextBytes.length - n];
        System.arraycopy(buffer, n, plaintextBytes, 0,
                plaintextBytes.length);

        return plaintextBytes;
    }
}

Related

  1. decrypt(byte[] serialize)
  2. decrypt(int encrypted, int salt)
  3. decrypt(String arg0)
  4. decrypt(String data, String key)