Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: how to decode this java encode

  1. #1
    Junior Member
    Join Date
    Apr 2021
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to decode this java encode

    this android java script encode its data before swnding to server.
    How to decode it.


    package com.app;

    import android.content.Intent;
    import android.net.Uri.Builder;
    import android.os.Bundle;
    import android.view.View;
    import androidx.appcompat.app.AppCompatActivity;
    import androidx.recyclerview.widget.LinearLayoutManager;
    import androidx.recyclerview.widget.RecyclerView;
    import androidx.recyclerview.widget.RecyclerView.OnScroll Listener;
    import com.app.RVAdapter.ItemClickListener;
    import java.io.BufferedInputStream;
    import java.io.BufferedWriter;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.io.OutputStreamWriter;
    import java.math.BigInteger;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.util.ArrayList;
    import java.util.Base64;
    import javax.net.ssl.HttpsURLConnection;
    import org.json.JSONArray;
    import org.json.JSONObject;

    public class DreamInterpreterActivity extends AppCompatActivity implements ItemClickListener {
    static final /* synthetic */ boolean $assertionsDisabled = false;
    BigInteger N;
    BigInteger P;
    BigInteger PHI;
    BigInteger Q;
    ArrayList<AppBean> contentList;
    BigInteger d;
    BigInteger e;
    String lang;
    Boolean loading = Boolean.valueOf(false);
    int page = 1;
    byte[] param1;
    byte[] param2;
    byte[] param3;
    byte[] param4;
    byte[] param5;
    RVAdapter radapter;
    RecyclerView recyclerView;

    public class LoadContentNamea extends Thread {
    String cat = "dreaminterpret";
    String lang;
    String page = "1";
    String service = "APP";
    String uri;

    public LoadContentNamea(String str, String str2) {
    this.lang = str2;
    this.uri = str;
    }

    public void run() {
    loadName();
    }

    public void loadName() {
    try {
    HttpsURLConnection httpsURLConnection = (HttpsURLConnection) new URL(this.uri).openConnection();
    httpsURLConnection.setRequestMethod("POST");
    httpsURLConnection.setDoInput(true);
    httpsURLConnection.setDoOutput(true);
    OutputStream outputStream = httpsURLConnection.getOutputStream();
    BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
    DreamInterpreterActivity.this.param1 = encryptMessage(this.service.getBytes());
    DreamInterpreterActivity.this.param2 = encryptMessage(this.cat.getBytes());
    DreamInterpreterActivity.this.param3 = encryptMessage(this.page.getBytes());
    DreamInterpreterActivity.this.param4 = encryptMessage(this.lang.getBytes());
    bufferedWriter.write(new Builder().appendQueryParameter("service", Base64.getEncoder().encodeToString(DreamInterprete rActivity.this.param1)).appendQueryParameter("cat" , Base64.getEncoder().encodeToString(DreamInterprete rActivity.this.param2)).appendQueryParameter("page ", Base64.getEncoder().encodeToString(DreamInterprete rActivity.this.param3)).appendQueryParameter("lang ", Base64.getEncoder().encodeToString(DreamInterprete rActivity.this.param4)).build().getEncodedQuery()) ;
    bufferedWriter.flush();
    bufferedWriter.close();
    outputStream.close();
    httpsURLConnection.connect();
    InputStreamReader inputStreamReader = new InputStreamReader(new BufferedInputStream(httpsURLConnection.getInputStr eam()));
    String str = "";
    for (int read = inputStreamReader.read(); read != -1; read = inputStreamReader.read()) {
    str = str + ((char) read);
    }
    DreamInterpreterActivity.this.contentList.clear();
    JSONArray jSONArray = new JSONArray(new JSONObject(str).getString("content"));
    for (int i = 0; i < jSONArray.length(); i++) {
    JSONObject jSONObject = jSONArray.getJSONObject(i);
    DreamInterpreterActivity.this.contentList.add(new AppBean(jSONObject.getString("title"), jSONObject.getString("desc"), jSONObject.getString("url")));
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    DreamInterpreterActivity.this.runOnUiThread(new Runnable() {
    public void run() {
    try {
    DreamInterpreterActivity.this.recyclerView.setAdap ter(DreamInterpreterActivity.this.radapter);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    });
    }

    public byte[] encryptMessage(byte[] bArr) {
    return new BigInteger(bArr).modPow(DreamInterpreterActivity.t his.e, DreamInterpreterActivity.this.N).toByteArray();
    }
    }

    public class LoadContentPagea extends Thread {
    String cat = "dreaminterpret";
    String lang;
    int page;
    String service = "APP";
    String uri;

    public LoadContentPagea(String str, String str2, int i) {
    this.lang = str2;
    this.page = i;
    this.uri = str;
    }

    public void run() {
    loadName();
    }

    public void loadName() {
    try {
    HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(this.uri).openConnection();
    httpURLConnection.setRequestMethod("POST");
    httpURLConnection.setDoInput(true);
    httpURLConnection.setDoOutput(true);
    OutputStream outputStream = httpURLConnection.getOutputStream();
    BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
    DreamInterpreterActivity.this.param1 = encryptMessage(this.service.getBytes());
    DreamInterpreterActivity.this.param2 = encryptMessage(this.cat.getBytes());
    DreamInterpreterActivity.this.param3 = encryptMessage(this.lang.getBytes());
    DreamInterpreterActivity.this.param4 = encryptMessage(String.valueOf(this.page).getBytes( ));
    bufferedWriter.write(new Builder().appendQueryParameter("service", Base64.getEncoder().encodeToString(DreamInterprete rActivity.this.param1)).appendQueryParameter("cat" , Base64.getEncoder().encodeToString(DreamInterprete rActivity.this.param2)).appendQueryParameter("lang ", Base64.getEncoder().encodeToString(DreamInterprete rActivity.this.param3)).appendQueryParameter("page ", Base64.getEncoder().encodeToString(DreamInterprete rActivity.this.param4)).build().getEncodedQuery()) ;
    bufferedWriter.flush();
    bufferedWriter.close();
    outputStream.close();
    httpURLConnection.connect();
    InputStreamReader inputStreamReader = new InputStreamReader(new BufferedInputStream(httpURLConnection.getInputStre am()));
    String str = "";
    for (int read = inputStreamReader.read(); read != -1; read = inputStreamReader.read()) {
    str = str + ((char) read);
    }
    JSONArray jSONArray = new JSONArray(new JSONObject(str).getString("content"));
    for (int i = 0; i < jSONArray.length(); i++) {
    JSONObject jSONObject = jSONArray.getJSONObject(i);
    DreamInterpreterActivity.this.radapter.addItem(new AppBean(jSONObject.getString("title"), jSONObject.getString("desc"), jSONObject.getString("url")), DreamInterpreterActivity.this.radapter.getItemCoun t());
    }
    DreamInterpreterActivity.this.loading = Boolean.valueOf(false);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    public byte[] encryptMessage(byte[] bArr) {
    return new BigInteger(bArr).modPow(DreamInterpreterActivity.t his.e, DreamInterpreterActivity.this.N).toByteArray();
    }
    }

    protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(2131558428);
    setTitle(getIntent().getStringExtra("title"));
    getSupportActionBar().setDisplayHomeAsUpEnabled(tr ue);
    this.lang = getSharedPreferences("SharedPStarter", null).getString("lang", "en");
    bundle = new ArrayList();
    this.contentList = bundle;
    String str = "";
    bundle.add(new AppBean("....", str, str, str));
    this.P = new BigInteger("15531264523032092445061482367039862261 01073803652684979219159091230094020310263339292786 62088657907130837223635828264753869964405361830526 94548126782024071096720296475981529992268440853168 20946882098910988844641079508175103482966364984804 84668564549263259489994437590053411791522985751406 648572583536572730339");
    bundle = new BigInteger("12567543114943531465972923509396892665 08794029848363082650550036427689330583480231634199 99026296585335843640068292735772411686492962278789 97072989895447873650503591608816876410215034745547 00817480083529392220596218550490953616343761954959 98795426343384734273252093585426952828182015434219 718994352231162016873");
    this.Q = bundle;
    this.N = this.P.multiply(bundle);
    this.PHI = this.P.subtract(BigInteger.ONE).multiply(this.Q.su btract(BigInteger.ONE));
    this.e = new BigInteger("72218869861855126248782339845073418099 10885989969871150112836183513172779370631312755231 61328944344951022593615317670859665941689291703018 5338371794861199");
    while (this.PHI.gcd(this.e).compareTo(BigInteger.ONE) > null && this.e.compareTo(this.PHI) < null) {
    this.e.add(BigInteger.ONE);
    System.out.println(this.e);
    }
    RecyclerView recyclerView = (RecyclerView) findViewById(2131362211);
    this.recyclerView = recyclerView;
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    bundle = new RVAdapter(this, this.contentList, "dreaninterpret");
    this.radapter = bundle;
    bundle.setClickListener(this);
    this.recyclerView.setAdapter(this.radapter);
    this.recyclerView.addOnScrollListener(new OnScrollListener() {
    public void onScrollStateChanged(RecyclerView recyclerView, int i) {
    Boolean valueOf = Boolean.valueOf(true);
    if (recyclerView.canScrollVertically(1) != null) {
    return;
    }
    if (DreamInterpreterActivity.this.loading.booleanValu e() == null) {
    DreamInterpreterActivity.this.loading = valueOf;
    recyclerView = DreamInterpreterActivity.this;
    recyclerView.page++;
    i = DreamInterpreterActivity.this;
    new LoadContentPagea("https://site.com", i.lang, DreamInterpreterActivity.this.page).start();
    return;
    }
    DreamInterpreterActivity.this.loading = valueOf;
    }
    });
    new LoadContentNamea("https://site.com", this.lang).start();
    }

    public void onItemClick(View view, int i) {
    view = new Intent(this, ItemPlayer.class);
    view.putExtra("title", ((AppBean) this.contentList.get(i)).getTitle());
    view.putExtra("desc", ((AppBean) this.contentList.get(i)).getDesc());
    view.putExtra("url", "/DreamInterpretor/" + this.lang + "/" + ((AppBean) this.contentList.get(i)).getUrl());
    startActivity(view);
    }

    public boolean onSupportNavigateUp() {
    finish();
    return true;
    }
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: how to decode this java encode

    Can you ask the author of that code for the solution?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [Help] A simple encode and decode program
    By Cheesepro in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 28th, 2014, 07:03 PM
  2. how to decode the html tags in java?
    By swarupa.d in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 16th, 2014, 05:56 AM
  3. Ability to decode Java JAR files
    By J697 in forum Java Theory & Questions
    Replies: 3
    Last Post: October 13th, 2012, 10:32 AM
  4. [SOLVED] Help reading a file to decode or encode
    By mickey2012 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 29th, 2012, 10:46 PM
  5. Encode and decode - Caesar cipher
    By siabanie in forum Java Theory & Questions
    Replies: 1
    Last Post: October 7th, 2011, 06:25 PM

Tags for this Thread