CC2538之TinyOS例程实验:6-CCM(AES)实验

本例程参考TI cc2538_foundation_firmware_1_0_1_0\driverlib\cc2538\examples\ccm例程修改而来;

创建c文件,和第五部做法一样,TinyOS直接使用C文件;

cc2538_ccm.h文件

#ifndef CC2538AES_CCM_H
#define CC2538AES_CCM_H
#ifdef CC2538_HW_SECURITY 


#define AUTHENTICATION_LENTH     0X4    
typedef struct
{
    uint8_t  ui8CCMKey[16];             // Key
    uint8_t  ui8CCMMval;                // length of authentication
    uint8_t  ui8CCMN[13];               // Nonce
    uint8_t* ui8CCMA;                   // Additional data
    uint8_t* ui8CCMInPut;               // input message
    uint16_t ui16CCMInPutLen;           // length of message
    uint16_t ui16CCMLenA;               // length of additional data
    uint8_t  ui8CCMKeyLocation;    
1.古典密码算法之 替代算法 import java.io.*; public class Caesar { //向右加密方法 ming为明文 mi 为密文 yao为密钥 public static void encode(String ming, int yao) { String mi = ""; for(int i=0; i<ming.length(); i++){ if (ming.charAt(i) == 32) mi += (char)(32); else if (ming.charAt(i) >= 'a' && ming.charAt(i) <= 'z') mi += (char)('a' + ((ming.charAt(i) - 'a' + yao) % 26)); else if (ming.charAt(i) >= 'A' && ming.charAt(i) <= 'Z') mi += (char)('A' + ((ming.charAt(i) - 'A' + yao) % 26)); else if (ming.charAt(i) >= '0' && ming.charAt(i) <= '9') mi += (char)('0' + ((ming.charAt(i) - '0' + yao) % 10)); } System.out.println("密文为: " + mi); } /* * 2.古典密码算法之 置换算法 * */ public class Change { //当加密或者解密成功时返回CRYPT_OK,失败时返回CRYPT_ERROR private final static int CRYPT_OK = 1; private final static int CRYPT_ERROR = 0; /* * @param initCode 没有加密前的字符串 * @CRYPT_OK 加密成功 * @CRYPT_ERROR 加密失败 */ public static int encrypt(String initCode) throws Exception{ //用来输出加密后的字符 StringBuilder sb = new StringBuilder(); //获取initCode的字符串长度 int codeLength = initCode.length(); //根据这个codeLength来确定要几行6列 int rows = (int)Math.ceil(codeLength/6.0 ); //构造一个rows行6列的数组 char[][] initChar = new char[rows][6]; //存放initCode中的所有字符,包括空格 for(int i = 0; i < initChar.length; i++ ) for(int j=0; j < initChar[0].length; j++){ //将对应字符放入这个数组中 try{ initChar[i][j] = initCode.charAt( (i ) * initChar[0].length + j ); }catch(Exception e){
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值