网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
07月14日漏签0天
aide吧 关注:33,059贴子:273,026
  • 看贴

  • 图片

  • 吧主推荐

  • 游戏

  • 1 2 下一页 尾页
  • 41回复贴,共2页
  • ,跳到 页  
<<返回aide吧
>0< 加载中...

【水帖】我的弱智加密解密算法

  • 只看楼主
  • 收藏

  • 回复
  • Seven_Sign
  • 自成一派
    12
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
private static final int BUFFER = 40960;
public static void jiami (byte[] bytes)
{
for (int i=0;i < bytes.length;i++)
{
bytes[i] = (byte)(bytes[i] + 1);
}
}
public static File jiami (File srcFile) throws IOException
{
if (!srcFile.isFile())
{
throw new IOException("specified file not exist or isnot a file");
}
File dstFile = new File(srcFile.getAbsolutePath() + ".jiami");
dstFile.createNewFile();
byte[] buffer = new byte[BUFFER];
FileInputStream fis = new FileInputStream(srcFile);
FileOutputStream fos = new FileOutputStream(dstFile);
final int sizeInAll = fis.available();
long sizeSum = 0;
int bufferSize = 0;
long startTime = System.currentTimeMillis();
long lastProgress = 0;
while ((bufferSize = fis.read(buffer)) != -1)
{
jiami(buffer);
fos.write(buffer);
fos.flush();
sizeSum += bufferSize;
int progress = (int)(100 * sizeSum / sizeInAll);
if (progress > lastProgress)
{
System.out.println("当前进度 : " + progress + "%");
lastProgress = progress;
}
}
fis.close();
fos.close();
System.out.println("加密完成 用时" + ((System.currentTimeMillis() - startTime)) + "毫秒");
System.out.println("文件大小 " + sizeInAll);
return dstFile;
}
public static void jiemi (byte[] bytes)
{
for (int i=0;i < bytes.length;i++)
{
bytes[i] = (byte)(bytes[i] - 1);
}
}
public static File jiemi (File srcFile) throws IOException
{
if (!srcFile.isFile())
{
throw new IOException("specified file not exist or isnot a file");
}
File dstFile = new File(srcFile.getAbsolutePath() + ".jiemi");
dstFile.createNewFile();
byte[] buffer = new byte[BUFFER];
FileInputStream fis = new FileInputStream(srcFile);
FileOutputStream fos = new FileOutputStream(dstFile);
final long sizeInAll = fis.available();
long sizeSum = 0;
int bufferSize = 0;
long startTime = System.currentTimeMillis();
int lastProgress = 0;
while ((bufferSize = fis.read(buffer)) != -1)
{
jiemi(buffer);
fos.write(buffer);
fos.flush();
sizeSum += bufferSize;
int progress = (int)(100 * sizeSum / sizeInAll);
if (progress > lastProgress)
{
System.out.println("当前进度 : " + progress + "%");
lastProgress = progress;
}
}
fis.close();
fos.close();
System.out.println("解密完成 用时" + ((System.currentTimeMillis() - startTime)) + "毫秒");
System.out.println("文件大小 " + sizeInAll);
return dstFile;
}
public static void main (String[] args) throws IOException
{
File testFile = new File("/sdcard/test");
jiemi(jiami(testFile));
}


  • Seven_Sign
  • 自成一派
    12
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
我测试过了,加密解密一个160M的文件大概需要40秒(缓冲数组是20K的,我换成2M的以后发现还慢了几秒←_←@缄默no )


2025-07-14 21:16:13
广告
  • 傻子的_love
  • 武林盟主
    14
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
我去,拼音


  • 花花画海海
  • 一代宗师
    15
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
顶你


  • Seven_Sign
  • 自成一派
    12
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
加密的核心就是
jiami(byte[])
jiemi(byte[])两个方法
改一下就能达到新的加解密方式


  • Seven_Sign
  • 自成一派
    12
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
1楼的加解密算法破解应该较容易(对于大神来说。。)


  • Seven_Sign
  • 自成一派
    12
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
快来一起写算法,看看谁的加密解密算法最叼


  • Seven_Sign
  • 自成一派
    12
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
//模板
public static void jiami (byte[] bytes)
{
for (int i=0;i < bytes.length;i++)
{
bytes[i] =
}
}
public static void jiemi (byte[] bytes)
{
for (int i=0;i < bytes.length;i++)
{
bytes[i] =
}
}


2025-07-14 21:10:13
广告
  • 缄默no
  • 人中龙凤
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
→_→我的是异或→_→


  • 沫湮_
  • 名震江湖
    13
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
文件加密算法木有,登陆加密算法倒是有两个,求破。。。。


  • 沫湮_
  • 名震江湖
    13
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
public static String MD5(String originalText) throws Exception {
byte buf[] = originalText.getBytes("ISO-8859-1");
StringBuffer hexString = new StringBuffer();
String result = "";
String digit = "";
try {
MessageDigest algorithm = MessageDigest.getInstance("MD5");
algorithm.reset();
algorithm.update(buf);
byte[] digest = algorithm.digest();
for (int i = 0; i < digest.length; i++) {
digit = Integer.toHexString(0xFF & digest[i]);
if (digit.length() == 1) {
digit = '0' + digit;
}
hexString.append(digit);
}
result = hexString.toString();
} catch (Exception ex) {
result = "";
}
return result.toUpperCase();
}


  • 沫湮_
  • 名震江湖
    13
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
public static String hexchar2bin(String md5str) throws UnsupportedEncodingException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(md5str.length() / 2);
for (int i = 0; i < md5str.length(); i=i+2){
baos.write((HEXSTRING.indexOf(md5str.charAt(i)) << 4 | HEXSTRING.indexOf(md5str.charAt(i + 1))));
}
return new String(baos.toByteArray(), "ISO-8859-1");
}


  • pansong291PS
  • 名震江湖
    13
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
//看看我的怎么样
//
public static void jiami (byte[] bytes)
{
for (int i=0;i < bytes.length;i++)
{
System.out.println(bytes[i]);
}
}
public static void jiemi (byte[] bytes)
{
for (int i=0;i < bytes.length;i++)
{
System.out.println(bytes[i]);
}
}
/*
小伙子你很有想法,跟我学做菜吧。
*/


  • 缄默no
  • 人中龙凤
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
public class StringCrypto {
public static String encrypt(String seed, String cleartext) throws Exception {
byte[] rawKey = getRawKey(seed.getBytes());
byte[] result = encrypt(rawKey, cleartext.getBytes());
return toHex(result);
}
public static String decrypt(String seed, String encrypted) throws Exception {
byte[] rawKey = getRawKey(seed.getBytes());
byte[] enc = toByte(encrypted);
byte[] result = decrypt(rawKey, enc);
return new String(result);
}
private static byte[] getRawKey(byte[] seed) throws Exception {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
sr.setSeed(seed);
kgen.init(128, sr); // 192 and 256 bits may not be available
SecretKey skey = kgen.generateKey();
byte[] raw = skey.getEncoded();
return raw;
}


2025-07-14 21:04:13
广告
  • 缄默no
  • 人中龙凤
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception {
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(clear);
return encrypted;
}
private static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception {
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
byte[] decrypted = cipher.doFinal(encrypted);
return decrypted;
}
public static String toHex(String txt) {
return toHex(txt.getBytes());
}
public static String fromHex(String hex) {
return new String(toByte(hex));
}
public static byte[] toByte(String hexString) {
int len = hexString.length()/2;
byte[] result = new byte[len];
for (int i = 0; i < len; i++)
result[i] = Integer.valueOf(hexString.substring(2*i, 2*i+2), 16).byteValue();
return result;
}


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 1 2 下一页 尾页
  • 41回复贴,共2页
  • ,跳到 页  
<<返回aide吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示