Java使用异或运算实现简单的加密解密算法实例代码

网友投稿 389 2023-03-04


Java使用异或运算实现简单的加密解密算法实例代码

java简单的加密解密算法,使用异或运算

实例1:

package cn.std.util;

import java.nio.charset.Charset;

public classVZSRcPf DeEnCode {

private static final String key0 = "FECOI()*&

private static final Charset charset = Charset.forName("UTF-8");

private static byte[] keyBytes = key0.getBytes(charset);

public static String encode(String enc){

byte[] b = enc.getBytes(charset);

for (int i=0,size=b.length;i

for (byte keyBytes0:keyBytes){

b[i] = (byte) (b[i]^keyBytes0);

}

}

return new String(b);

}

public static String decode(String dec){

byte[] e = dec.getBytes(charset);

byte[] dee = e;

for (int i=0,size=e.length;i

for (byte keyBytes0:keyBytes){

e[i] = (byte) (dee[i]^keyBytes0);

}

}

return new String(e);

}

public static void main(String[] args) {

String s="you are right";

String enc = encode(s);

String dec = decode(enc);

System.out.println(enc);

System.out.println(dec);

}

}

实例2

public static String setEncrypt(String str){

String sn="ziyu";

//密钥

int[] snNum=new int[str.length()];

String result="";

String temp="";

for (int i=0,j=0;i

if(j==sn.length())

j=0;

snNum[i]=str.charAt(i)^sn.charAt(j);

}

for (int k=0;k

if(snNum[k]<10){

temp="00"+snNum[k];

} else{

if(snNum[k]<100){

temp="0"+snNum[k];

}

}

result+=temp;

}

return result;

}

public static String getEncrypt(String str){

String sn="ziyu";

//密钥

char[] snNum=new chahttp://r[str.length()/3];

String result="";

for (int i=0,j=0;i

if(j==sn.length())

j=0;

int n=Integer.parseint(str.substring(i*3,i*3+3));

snNum[i]VZSRcPf=(char)((char)n^sn.charAt(j));

}

for (int k=0;k

result+=snNum[k];

}

return result;

}

}

总结

以上就是本文关于Java使用异或运算实现简单的加密解密算法实例代码的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

private static final Charset charset = Charset.forName("UTF-8");

private static byte[] keyBytes = key0.getBytes(charset);

public static String encode(String enc){

byte[] b = enc.getBytes(charset);

for (int i=0,size=b.length;i

for (byte keyBytes0:keyBytes){

b[i] = (byte) (b[i]^keyBytes0);

}

}

return new String(b);

}

public static String decode(String dec){

byte[] e = dec.getBytes(charset);

byte[] dee = e;

for (int i=0,size=e.length;i

for (byte keyBytes0:keyBytes){

e[i] = (byte) (dee[i]^keyBytes0);

}

}

return new String(e);

}

public static void main(String[] args) {

String s="you are right";

String enc = encode(s);

String dec = decode(enc);

System.out.println(enc);

System.out.println(dec);

}

}

实例2

public static String setEncrypt(String str){

String sn="ziyu";

//密钥

int[] snNum=new int[str.length()];

String result="";

String temp="";

for (int i=0,j=0;i

if(j==sn.length())

j=0;

snNum[i]=str.charAt(i)^sn.charAt(j);

}

for (int k=0;k

if(snNum[k]<10){

temp="00"+snNum[k];

} else{

if(snNum[k]<100){

temp="0"+snNum[k];

}

}

result+=temp;

}

return result;

}

public static String getEncrypt(String str){

String sn="ziyu";

//密钥

char[] snNum=new chahttp://r[str.length()/3];

String result="";

for (int i=0,j=0;i

if(j==sn.length())

j=0;

int n=Integer.parseint(str.substring(i*3,i*3+3));

snNum[i]VZSRcPf=(char)((char)n^sn.charAt(j));

}

for (int k=0;k

result+=snNum[k];

}

return result;

}

}

总结

以上就是本文关于Java使用异或运算实现简单的加密解密算法实例代码的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

for (byte keyBytes0:keyBytes){

b[i] = (byte) (b[i]^keyBytes0);

}

}

return new String(b);

}

public static String decode(String dec){

byte[] e = dec.getBytes(charset);

byte[] dee = e;

for (int i=0,size=e.length;i

for (byte keyBytes0:keyBytes){

e[i] = (byte) (dee[i]^keyBytes0);

}

}

return new String(e);

}

public static void main(String[] args) {

String s="you are right";

String enc = encode(s);

String dec = decode(enc);

System.out.println(enc);

System.out.println(dec);

}

}

实例2

public static String setEncrypt(String str){

String sn="ziyu";

//密钥

int[] snNum=new int[str.length()];

String result="";

String temp="";

for (int i=0,j=0;i

if(j==sn.length())

j=0;

snNum[i]=str.charAt(i)^sn.charAt(j);

}

for (int k=0;k

if(snNum[k]<10){

temp="00"+snNum[k];

} else{

if(snNum[k]<100){

temp="0"+snNum[k];

}

}

result+=temp;

}

return result;

}

public static String getEncrypt(String str){

String sn="ziyu";

//密钥

char[] snNum=new chahttp://r[str.length()/3];

String result="";

for (int i=0,j=0;i

if(j==sn.length())

j=0;

int n=Integer.parseint(str.substring(i*3,i*3+3));

snNum[i]VZSRcPf=(char)((char)n^sn.charAt(j));

}

for (int k=0;k

result+=snNum[k];

}

return result;

}

}

总结

以上就是本文关于Java使用异或运算实现简单的加密解密算法实例代码的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

for (byte keyBytes0:keyBytes){

e[i] = (byte) (dee[i]^keyBytes0);

}

}

return new String(e);

}

public static void main(String[] args) {

String s="you are right";

String enc = encode(s);

String dec = decode(enc);

System.out.println(enc);

System.out.println(dec);

}

}

实例2

public static String setEncrypt(String str){

String sn="ziyu";

//密钥

int[] snNum=new int[str.length()];

String result="";

String temp="";

for (int i=0,j=0;i

if(j==sn.length())

j=0;

snNum[i]=str.charAt(i)^sn.charAt(j);

}

for (int k=0;k

if(snNum[k]<10){

temp="00"+snNum[k];

} else{

if(snNum[k]<100){

temp="0"+snNum[k];

}

}

result+=temp;

}

return result;

}

public static String getEncrypt(String str){

String sn="ziyu";

//密钥

char[] snNum=new chahttp://r[str.length()/3];

String result="";

for (int i=0,j=0;i

if(j==sn.length())

j=0;

int n=Integer.parseint(str.substring(i*3,i*3+3));

snNum[i]VZSRcPf=(char)((char)n^sn.charAt(j));

}

for (int k=0;k

result+=snNum[k];

}

return result;

}

}

总结

以上就是本文关于Java使用异或运算实现简单的加密解密算法实例代码的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

if(j==sn.length())

j=0;

snNum[i]=str.charAt(i)^sn.charAt(j);

}

for (int k=0;k

if(snNum[k]<10){

temp="00"+snNum[k];

} else{

if(snNum[k]<100){

temp="0"+snNum[k];

}

}

result+=temp;

}

return result;

}

public static String getEncrypt(String str){

String sn="ziyu";

//密钥

char[] snNum=new chahttp://r[str.length()/3];

String result="";

for (int i=0,j=0;i

if(j==sn.length())

j=0;

int n=Integer.parseint(str.substring(i*3,i*3+3));

snNum[i]VZSRcPf=(char)((char)n^sn.charAt(j));

}

for (int k=0;k

result+=snNum[k];

}

return result;

}

}

总结

以上就是本文关于Java使用异或运算实现简单的加密解密算法实例代码的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

if(snNum[k]<10){

temp="00"+snNum[k];

} else{

if(snNum[k]<100){

temp="0"+snNum[k];

}

}

result+=temp;

}

return result;

}

public static String getEncrypt(String str){

String sn="ziyu";

//密钥

char[] snNum=new chahttp://r[str.length()/3];

String result="";

for (int i=0,j=0;i

if(j==sn.length())

j=0;

int n=Integer.parseint(str.substring(i*3,i*3+3));

snNum[i]VZSRcPf=(char)((char)n^sn.charAt(j));

}

for (int k=0;k

result+=snNum[k];

}

return result;

}

}

总结

以上就是本文关于Java使用异或运算实现简单的加密解密算法实例代码的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

if(j==sn.length())

j=0;

int n=Integer.parseint(str.substring(i*3,i*3+3));

snNum[i]VZSRcPf=(char)((char)n^sn.charAt(j));

}

for (int k=0;k

result+=snNum[k];

}

return result;

}

}

总结

以上就是本文关于Java使用异或运算实现简单的加密解密算法实例代码的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

result+=snNum[k];

}

return result;

}

}

总结

以上就是本文关于Java使用异或运算实现简单的加密解密算法实例代码的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:接口测试用例设计(接口测试用例设计要考虑)
下一篇:swing jtextArea滚动条和文字缩放效果
相关文章

 发表评论

暂时没有评论,来抢沙发吧~