For Programmers: Free Programming Magazines  


Home > Archive > Java Security > September 2006 > algorithm_on_2_handy_installed_but_different_output________need_help!!!!









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author algorithm_on_2_handy_installed_but_different_output________need_help!!!!
java_Programm_midp2.0

2006-09-15, 10:01 pm

package utils;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
import java.util.TimeZone;
import Stumbler;
public final class SMSCodec {
final static int KEYLEN = 10;

static public String createTimeString(Date dTimestamp){
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Europa/Berlin"));
if (dTimestamp != null)
cal.setTime(dTimestamp);

String strMin, strHour, strDay, strMonth;

strMin = String.valueOf(cal.get(Calendar.MINUTE));
strHour = String.valueOf(cal.get(Calendar.HOUR_OF_DAY));
strDay = String.valueOf(cal.get(Calendar.DAY_OF_MONTH) +1);
strMonth = String.valueOf(cal.get(Calendar.MONTH));


if(strMin.length() == 1 ){
strMin = 0 + strMin;
}

if(strHour.length() == 1){
strHour = 0 + strHour;
}

if(strDay.length() == 1 ){
strDay = 0 + strDay;
}

if(strMonth.length() == 1){
strMonth = 0 + strMonth;
}

String strDate = strDay + "." + strMonth + " " + strHour + ":" + strMin;
return strDate;
}

static public byte[] crypt(String Message, String recCode) {
byte[] returnArray = new byte[Message.length()+ KEYLEN];

recCode = MD5.computeMD5(recCode);

// Zufallszahl erstellen
Random r = new Random();
byte[] actKey = new byte[KEYLEN];
int y = 0, y2 = 0;
for (int i=0 ; i<KEYLEN; i++)
actKey[i] = (byte)(r.nextInt());
// damit die Nachricht verschluesseln
y = 0;
for ( int x = 0; x < Message.length(); x++) {
if (y == KEYLEN ) y = 0;

byte cs = (byte)Message.charAt(x);
byte kl = actKey[y];

returnArray[x + KEYLEN] = (byte)(cs ^ kl);
y++;
}

// mit time und Empfängernummer den Keyverxoren
y = 0;
y2 = 0;
for ( int i = 0; i< KEYLEN; i++){
if (y == createTimeString(null).length() ) y = 0;
if (y2 == recCode.length() ) y2 = 0;

returnArray[i] = (byte)((byte)createTimeString(null).charAt(y) ^ actKey[i]);
returnArray[i] = (byte)((byte)returnArray[i] ^ (byte)recCode.charAt(y2));
y++;
y2++;
}
return returnArray;
}

static public String decrypt(String time, byte[] data) {
byte[] actKey = new byte[KEYLEN];
String newMessage = "";

String recCode = MD5.computeMD5(SMSStumbler.SENDER);

// Schlüssel extrahieren
int y = 0;
int y2 = 0;

for (int i=0 ; i < KEYLEN; i++){
if (y == time.length() ) y = 0;
if (y2 == recCode.length() ) y2 = 0;

byte cs = (byte)time.charAt(y);
byte kl = (byte) ((byte)data[i] ^ (byte)recCode.charAt(y2));

actKey[i] = (byte)(kl ^ cs);
y++;
y2++;
}

// damit die Nachricht entschluesseln
y = 0;
for ( int x = 10; x < data.length; x++) {
if (y == KEYLEN ) y = 0;

byte cs = data[x];
byte kl = actKey[y];

newMessage += String.valueOf((char)(cs ^ kl));
y++;
}
return newMessage;
}
}
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com