當前位置:首頁 » 操作系統 » javacrc校驗演算法

javacrc校驗演算法

發布時間: 2022-03-14 10:48:59

Ⅰ crc校驗求java到啊

public class CRC16 { public static String crc16(String src,int len){
int crc = 0x0000FFFF;
short tc;
char sbit;
for(int i=0;i<len; i++){
tc = (short)(crc >>>8);
crc = ((tc ^ src.charAt(i)) & 0x00FF); for(int r=0;r<8;r++){
sbit = (char)(crc & 0x01);
crc >>>= 1; //�1�7�1�7�1�7�0�6�1�7�1�7�1�7�1�7�1�7�1�7�1�7�0�5λ
if(sbit != 0)crc =(crc^0xA001) & 0x0000FFFF; }
}
//Integer.toHexString(crc);
return Integer.toHexString(crc);
}
}

Ⅱ 求JAVA字元串CRC的計算代碼

需要看crc的演算法是具體是什麼。
比如如果是簡單的將各個位元組的值加起來作為crc的值。那麼可以將字元串轉換為數組,然後逐個位元組相加判斷crc是否正確。

Ⅲ 用java編寫一個獲得CRC校驗碼的javabean

private static String mkCrc16(String str) {
CRC16 crc16 = new CRC16();
byte[] b = str.getBytes();
for (int i = 0; i < b.length; i++)
crc16.update(b[i]);
return Integer.toHexString(crc16.value);
}

private static String mkCrc(String string) throws Exception {

CRC32 crc32 = new CRC32();
crc32.update(string.getBytes());

return Long.toHexString(crc32.getValue());
}

public class CRCUtil {
public static final int evalCRC16(byte[] data) {
int crc = 0xFFFF;
for (int i = 0; i < data.length; i++) {
crc = (data[i] << 8) ^ crc;
for (int j = 0; j < 8; ++j)
if ((crc & 0x8000) != 0)
crc = (crc << 1) ^ 0x1021;
else
crc <<= 1;
}

return (crc ^ 0xFFFF) & 0xFFFF;
}
}

Ⅳ 高分!用C++或JAVA編寫程序實現CRC校驗和奇偶校驗

位操作,c比較強大吧。。。。

Ⅳ 我現在要用Java做出crc32 的校驗,要求就是crc校驗,輸入一個數組,返回一個數組,返回的數組比原數組 * 多了

crc校驗返回的是一個和,校驗和,沒有你說的數組啊

Ⅵ java的crc8校驗,按指定多項式,求助

以下是我的分析,不知是否正確,你參考下1、首先來看你打java代碼:crc=(byte)((crc>>1)^0x8c);和 crc=(byte)(crc>>1); 導致這個問題是因為byte的最高位符號位,轉換的時候就出錯了2、示例代碼:package com.test;public class test {public static void main(String[] args) {byte[] ptr = { 1, 1, 1, 1, 1, 1 };byte res = getCrc(ptr);System.out.println();System.out.println((byte)( (1 >> 1) ^ 0x8c ) + ":" +( (1 >> 1) ^ 0x8c ) );}public static byte getCrc(byte[] ptr) {int crc = 0;for (int i = 0; i > 1) ^ 0x8c;} else {crc = crc >> 1;}}}return (byte) crc;}}

Ⅶ java 實現crc16校驗演算法的問題

貌似CRC演算法循環求余時減法是不帶借位的。

Ⅷ 如何用java實現CRC8驗證演算法

/*http://www.koders.com/java/.aspx?s=Address#L34
*---------------------------------------------------------------------------
* Copyright (C) 1999,2000 Dallas Semiconctor Corporation, All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, , modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above right notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Dallas Semiconctor
* shall not be used except as stated in the Dallas Semiconctor
* Branding Policy.
*---------------------------------------------------------------------------
*/

package com.dalsemi.onewire.utils;

/**
* CRC8 is a class to contain an implementation of the
* Cyclic-Rendency-Check CRC8 for the iButton. The CRC8 is used
* in the 1-Wire Network address of all iButtons and 1-Wire
* devices.
* <p>
* CRC8 is based on the polynomial = X^8 + X^5 + X^4 + 1.
*
* @version 0.00, 28 Aug 2000
* @author DS
*
*/
public class CRC8
{

//--------
//-------- Variables
//--------

/**
* CRC 8 lookup table
*/
private static byte dscrc_table [];

/*
* Create the lookup table
*/
static
{

//Translated from the assembly code in iButton Standards, page 129.
dscrc_table = new byte [256];

int acc;
int crc;

for (int i = 0; i < 256; i++)
{
acc = i;
crc = 0;

for (int j = 0; j < 8; j++)
{
if (((acc ^ crc) & 0x01) == 0x01)
{
crc = ((crc ^ 0x18) >> 1) | 0x80;
}
else
crc = crc >> 1;

acc = acc >> 1;
}

dscrc_table [i] = ( byte ) crc;
}
}

//--------
//-------- Constructor
//--------

/**
* Private constructor to prevent instantiation.
*/
private CRC8 ()
{
}

//--------
//-------- Methods
//--------

/**
* Perform the CRC8 on the data element based on the provided seed.
* <p>
* CRC8 is based on the polynomial = X^8 + X^5 + X^4 + 1.
*
* @param dataToCrc data element on which to perform the CRC8
* @param seed seed the CRC8 with this value
* @return CRC8 value
*/
public static int compute (int dataToCRC, int seed)
{
return (dscrc_table [(seed ^ dataToCRC) & 0x0FF] & 0x0FF);
}

/**
* Perform the CRC8 on the data element based on a zero seed.
* <p>
* CRC8 is based on the polynomial = X^8 + X^5 + X^4 + 1.
*
* @param dataToCrc data element on which to perform the CRC8
* @return CRC8 value
*/
public static int compute (int dataToCRC)
{
return (dscrc_table [dataToCRC & 0x0FF] & 0x0FF);
}

/**
* Perform the CRC8 on an array of data elements based on a
* zero seed.
* <p>
* CRC8 is based on the polynomial = X^8 + X^5 + X^4 + 1.
*
* @param dataToCrc array of data elements on which to perform the CRC8
* @return CRC8 value
*/
public static int compute (byte dataToCrc [])
{
return compute(dataToCrc, 0, dataToCrc.length);
}

/**
* Perform the CRC8 on an array of data elements based on a
* zero seed.
* <p>
* CRC8 is based on the polynomial = X^8 + X^5 + X^4 + 1.
*
* @param dataToCrc array of data elements on which to perform the CRC8
* @param off offset into array
* @param len length of data to crc
* @return CRC8 value
*/
public static int compute (byte dataToCrc [], int off, int len)
{
return compute(dataToCrc, off, len, 0);
}

/**
* Perform the CRC8 on an array of data elements based on the
* provided seed.
* <p>
* CRC8 is based on the polynomial = X^8 + X^5 + X^4 + 1.
*
* @param dataToCrc array of data elements on which to perform the CRC8
* @param off offset into array
* @param len length of data to crc
* @param seed seed to use for CRC8
* @return CRC8 value
*/
public static int compute (byte dataToCrc [], int off, int len, int seed)
{

// loop to do the crc on each data element
int CRC8 = seed;

for (int i = 0; i < len; i++)
CRC8 = dscrc_table [(CRC8 ^ dataToCrc [i + off]) & 0x0FF];

return (CRC8 & 0x0FF);
}

/**
* Perform the CRC8 on an array of data elements based on the
* provided seed.
* <p>
* CRC8 is based on the polynomial = X^8 + X^5 + X^4 + 1.
*
* @param dataToCrc array of data elements on which to perform the CRC8
* @param seed seed to use for CRC8
* @return CRC8 value
*/
public static int compute (byte dataToCrc [], int seed)
{
return compute(dataToCrc, 0, dataToCrc.length, seed);
}
}

Ⅸ 求java的 crc8演算法方法

你的意思就翻譯一下,是嗎:
static char crc8fun ( char in, char prest)
{
int loop;
char out;
char crc_pol=0xb8; /*多項式*/
out = in^prest;
for(loop=0;loop<8;loop++){
if(out&0x01){
out=(out>>1)^crc_pol;
}else{
out=(out>>1);
}
return out;
}
}

Ⅹ 將C語言版的CRC校驗改為java代碼寫

short CityComGetCRC(final byte[] data,short length){

shortcrc=0,q;
shortc,i;

for(i=0;i<length;i++){
c=data[i];
q=(crc^c)&0x0f;
crc=(crc>>4)^(q*0x1081);
q=(crc^(c>>4))&0xf0;
crc=(crc>>4)^(q*0x1081);
}

returncrc;
}
熱點內容
一年級數學分解演算法 發布:2024-11-15 15:41:08 瀏覽:410
安卓個人熱點怎麼分享 發布:2024-11-15 15:40:16 瀏覽:263
墊錢解壓 發布:2024-11-15 15:38:54 瀏覽:335
miui4相當於安卓什麼系統 發布:2024-11-15 15:37:54 瀏覽:708
rc4android 發布:2024-11-15 15:27:25 瀏覽:741
電腦伺服器機箱圖片 發布:2024-11-15 15:27:18 瀏覽:114
網頁緩存文件提取 發布:2024-11-15 15:24:42 瀏覽:144
sqlserver提高 發布:2024-11-15 15:24:40 瀏覽:659
太空工程師編程模塊 發布:2024-11-15 15:15:27 瀏覽:68
apache壓縮 發布:2024-11-15 15:11:54 瀏覽:245