Android Open Source - nsa-away Enter Ciphertext Activity






From Project

Back to project page nsa-away.

License

The source code is released under:

GNU General Public License

If you think the Android project nsa-away listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright 2014 individual contributors as indicated by the @author 
 * tags//from w  ww .j  a va2  s .co m
 * 
 * This is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this software.  If not, see <http://www.gnu.org/licenses/>. 
 */
package org.sector67.nsaaway;

import android.app.Activity;
import android.app.DialogFragment;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

/**
 * 
 * @author scott.hasse@gmail.com
 * 
 */
public class EnterCiphertextActivity extends Activity implements
    KeyChooserDialogFragment.KeyChooserDialogListener {

  private String keyName;
  private String incomingText = null;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_enter_ciphertext);

    
      SharedPreferences sharedPref = PreferenceManager
          .getDefaultSharedPreferences(this);
      String defaultDecryptKey = sharedPref.getString(
          SettingsActivity.KEY_PREF_DEFAULT_DECRYPT_KEY, "");
      onKeyChoice(defaultDecryptKey);

          Button chooseKeyForDecryptionButton = (Button) findViewById(R.id.chooseKeyForDecryptionButton);
          Button decryptTextButton = (Button) findViewById(R.id.decryptTextButton);
          Button buttonPasteFromClipboard = (Button) findViewById(R.id.buttonPasteFromClipboard);

        if (incomingText == null) {
          Intent i = getIntent();
          incomingText = i.getStringExtra(MainActivity.INCOMING_TEXT_KEY);
          EditText txtInput = (EditText) findViewById(R.id.ciphertextEditText);
          txtInput.setText(incomingText);
        }
        
          decryptTextButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View arg0) {
                    Intent nextScreen = new Intent(getApplicationContext(), DisplayPlaintextActivity.class);
                
                    EditText txtInput = (EditText)findViewById(R.id.ciphertextEditText);
                    String ciphertext = txtInput.getText().toString();
                    EditText offsetInput = (EditText)findViewById(R.id.keyOffsetEditText);
                    Integer offset = Integer.parseInt(offsetInput.getText().toString());
                
                    nextScreen.putExtra(MainActivity.CIPHERTEXT_KEY, ciphertext);
                    nextScreen.putExtra(MainActivity.KEYNAME_KEY, keyName);
                    nextScreen.putExtra(MainActivity.OFFSET_KEY, offset);
                    startActivity(nextScreen); 
                }
          });
          
          //Listen for a button event
          buttonPasteFromClipboard.setOnClickListener(new View.OnClickListener() {
                public void onClick(View arg0) {
                  // Gets a handle to the clipboard service.
                  ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                      ClipData clip = clipboard.getPrimaryClip();
                      
                    
                  EditText txtInput = (EditText)findViewById(R.id.ciphertextEditText);
                  txtInput.setText(clip.getItemAt(0).getText().toString());
              
                }
          });
          


    chooseKeyForDecryptionButton
        .setOnClickListener(new View.OnClickListener() {
          public void onClick(View arg0) {
            showKeyChooserDialog();
          }
        });
    
    //TODO: on ciphertext change, attempt to parse the offset from the envelope

  }

  private void showKeyChooserDialog() {
    // Create an instance of the dialog fragment and show it
    DialogFragment dialog = new KeyChooserDialogFragment();
    dialog.show(getFragmentManager(), "NoticeDialogFragment");
  }

  /*
   * This method is called when a key is chosen
   */
  @Override
  public void onKeyChoice(String name) {
    TextView keyString = (TextView) findViewById(R.id.keyNameValue);
    this.keyName = name;
    keyString.setText(name);
  }

}




Java Source Code List

org.sector67.nsaaway.CreateAKeyActivity.java
org.sector67.nsaaway.DisplayCiphertextActivity.java
org.sector67.nsaaway.DisplayPlaintextActivity.java
org.sector67.nsaaway.EnterCiphertextActivity.java
org.sector67.nsaaway.EnterPlaintextActivity.java
org.sector67.nsaaway.KeyChooserActivity.java
org.sector67.nsaaway.KeyChooserDialogFragment.java
org.sector67.nsaaway.KeyManagerActivity.java
org.sector67.nsaaway.MainActivity.java
org.sector67.nsaaway.SettingsActivity.java
org.sector67.nsaaway.SettingsFragment.java
org.sector67.nsaaway.SimpleOCRActivity.java
org.sector67.nsaaway.android.AlertUtils.java
org.sector67.nsaaway.file.AbstractFileUtils.java
org.sector67.nsaaway.file.DirectoryChooserActivity.java
org.sector67.nsaaway.file.FileUtilsFactory.java
org.sector67.nsaaway.file.FileUtils.java
org.sector67.nsaaway.file.KitKatFileUtils.java
org.sector67.nsaaway.file.LegacyFileUtils.java
org.sector67.nsaaway.key.KeyUtils.java
org.sector67.nsaaway.ocr.complex.BeepManager.java
org.sector67.nsaaway.ocr.complex.CaptureActivityHandler.java
org.sector67.nsaaway.ocr.complex.CaptureActivity.java
org.sector67.nsaaway.ocr.complex.DecodeHandler.java
org.sector67.nsaaway.ocr.complex.DecodeThread.java
org.sector67.nsaaway.ocr.complex.FinishListener.java
org.sector67.nsaaway.ocr.complex.HelpActivity.java
org.sector67.nsaaway.ocr.complex.LuminanceSource.java
org.sector67.nsaaway.ocr.complex.OcrCharacterHelper.java
org.sector67.nsaaway.ocr.complex.OcrInitAsyncTask.java
org.sector67.nsaaway.ocr.complex.OcrRecognizeAsyncTask.java
org.sector67.nsaaway.ocr.complex.OcrResultFailure.java
org.sector67.nsaaway.ocr.complex.OcrResultText.java
org.sector67.nsaaway.ocr.complex.OcrResult.java
org.sector67.nsaaway.ocr.complex.PlanarYUVLuminanceSource.java
org.sector67.nsaaway.ocr.complex.PreferencesActivity.java
org.sector67.nsaaway.ocr.complex.ViewfinderView.java
org.sector67.nsaaway.ocr.complex.camera.AutoFocusManager.java
org.sector67.nsaaway.ocr.complex.camera.CameraConfigurationManager.java
org.sector67.nsaaway.ocr.complex.camera.CameraManager.java
org.sector67.nsaaway.ocr.complex.camera.PreviewCallback.java
org.sector67.nsaaway.ocr.complex.camera.ShutterButton.java
org.sector67.nsaaway.ocr.complex.language.LanguageCodeHelper.java