I tried to do encrypted part by myself, it doesn't work. :( I attached it for you to look at.
On Sunday, May 29, 2016 at 10:40:49 AM UTC-4, hezaveh wrote: > > Hi, > > I want an android app, one EditText to enter input. and then a button, by > clicking the button it calls encrypt method and then a textview shows the > encrypted message. The other button to decrypt the message, calls decrypt > method. last textview shows the dencrypted message which is same as the > input. > > Here is a link that implement RSA encryption ( > https://sites.google.com/site/mobilesecuritylabware/3-data-location-privacy/lab-activity/cryptography/cryptography-mobile-labs/encryption-decryption/2-lab-activity/lab2-rsa-encryption-program-android-studio). > > I want exactly same for goldwasser micali. > > Thanks > > On Saturday, May 28, 2016 at 7:34:01 PM UTC-4, TreKing wrote: >> >> >> On Fri, May 27, 2016 at 4:17 PM, hezaveh <mari.h...@gmail.com> wrote: >> >>> I have a java code of goldwasser-micali encryption (attached), and I >>> need your help to implement it in android studio. can anybody help me? >>> >> >> Java code is not something you "implement" in Android Studio. What are >> you actually trying to achieve? >> >> >> ------------------------------------------------------------------------------------------------- >> TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago >> transit tracking app for Android-powered devices >> > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. To post to this group, send email to android-developers@googlegroups.com. Visit this group at https://groups.google.com/group/android-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/android-developers/a4bfd9b4-6c9d-4d9b-9b2a-28cc492c968f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
package com.example.goldwasser_micali; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.EditText; import java.math.BigInteger; import java.security.SecureRandom; public class MainActivity extends AppCompatActivity { /** * SYSTEM PARAMETERS */ //Bitsize private int bitSize; /** * KEYS */ //Private key private BigInteger p, q; //Public key private BigInteger x, n; //Random number generator public SecureRandom rand; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final Button enButton = (Button) findViewById(R.id.enbutton); final Button deButton = (Button) findViewById(R.id.debutton); final EditText input = (EditText) findViewById(R.id.Input); final EditText Raw = (EditText) findViewById(R.id.raw); final EditText output = (EditText) findViewById(R.id.OriginText); enButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String j = input.toString(); MainActivity gm = new MainActivity(512); for (int i = 0; i < j.length(); i++) { BigInteger c = gm.encrypt(j.charAt(i) == '1'); Raw.setText(c.toString()); } } }); } /** * Constructor generating key parameters * * @param bitSize: size in bits of p and q, this number must be a power of 2, for 1024 security bitSize must be 512. */ public MainActivity(int bitSize) { this.bitSize = bitSize; this.rand = new SecureRandom(); generateKeys(); } /** * Key parameters of Benaloh's cryptosystem */ public void generateKeys() { BigInteger one = BigInteger.ONE, two = new BigInteger("2"); p = randomNumber(true, bitSize); do { q = randomNumber(true, bitSize); } while (p.equals(q)); n = p.multiply(q); do { x = randomNumber(false, bitSize * 2); } while (x.compareTo(n) >= 0 || x.modPow(p.subtract(one).divide(two), p).equals(one) || x.modPow(q.subtract(one).divide(two), q).equals(one)); } /** * BigInteger random number generator * * @param prime true if the number must be prime, false otherwise * @param size: size in bits * @return random number with the criteria selected. */ private BigInteger randomNumber(boolean prime, int size) { if (prime) return BigInteger.probablePrime(size, rand); BigInteger number = null; byte bNumber[] = new byte[(int) Math.ceil(size / 8.0)]; do { rand.nextBytes(bNumber); number = new BigInteger(bNumber); } while (number.compareTo(BigInteger.ZERO) <= 0); return number; } public BigInteger encrypt(boolean bit) { BigInteger y; do { y = randomNumber(false, bitSize * 2); } while (y.compareTo(n) >= 0); return y.modPow(new BigInteger("2"), n).multiply(bit ? x : BigInteger.ONE).remainder(n); } public boolean decrypt(BigInteger c) { boolean qr; qr = c.modPow(p.subtract(BigInteger.ONE).divide(new BigInteger("2")), p).equals(BigInteger.ONE); qr &= c.modPow(q.subtract(BigInteger.ONE).divide(new BigInteger("2")), q).equals(BigInteger.ONE); return qr; } /** public static void main(String[] args) { String m = "101011101000011011111000000110101"; MainActivity gm = new MainActivity(512); System.out.println(m); for (int i = 0; i < m.length(); i++) { BigInteger c = gm.encrypt(m.charAt(i) == '1'); System.out.print((gm.decrypt(c) ? 0 : 1));} } **/ @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }