int rijndaelDecryptRound (word8 a[4][MAXBC], int keyBits, int blockBits, word8 rk[MAXROUNDS+1][4][MAXBC], int rounds) /* Decrypt only a certain number of rounds. * Only used in the Intermediate Value Known Answer Test. * Operations rearranged such that the intermediate values * of decryption correspond with the intermediate values * of encryption. */ { int r, BC, ROUNDS; switch (blockBits) { case 128: BC = 4; break; case 192: BC = 6; break; case 256: BC = 8; break; default : return (-2); } switch (keyBits >= blockBits ? keyBits : blockBits) { case 128: ROUNDS = 10; break; case 192: ROUNDS = 12; break; case 256: ROUNDS = 14; break; default : return (-3); /* this cannot happen */ } /* make number of rounds sane */ if (rounds > ROUNDS) rounds = ROUNDS; /* First the special round: * without InvMixColumn * with extra KeyAddition */ KeyAddition(a,rk[ROUNDS],BC); Substitution(a,Si,BC); ShiftRow(a,1,BC); /* ROUNDS-1 ordinary rounds */ for(r = ROUNDS-1; r > rounds; r--) { KeyAddition(a,rk[r],BC); InvMixColumn(a,BC); Substitution(a,Si,BC); ShiftRow(a,1,BC); } if (rounds == 0) { /* End with the extra key addition */ KeyAddition(a,rk[0],BC); } return 0; }
int _rijndaelDecrypt (word8 a[4][MAXBC], int keyBits, int blockBits, word8 rk[MAXROUNDS+1][4][MAXBC]) { int r, BC, ROUNDS; switch (blockBits) { case 128: BC = 4; break; case 192: BC = 6; break; case 256: BC = 8; break; default : return (-2); } switch (keyBits >= blockBits ? keyBits : blockBits) { case 128: ROUNDS = 10; break; case 192: ROUNDS = 12; break; case 256: ROUNDS = 14; break; default : return (-3); /* this cannot happen */ } /* To decrypt: apply the inverse operations of the encrypt routine, * in opposite order * * (KeyAddition is an involution: it 's equal to its inverse) * (the inverse of Substitution with table S is Substitution with the inverse table of S) * (the inverse of Shiftrow is Shiftrow over a suitable distance) */ /* First the special round: * without InvMixColumn * with extra KeyAddition */ KeyAddition(a,rk[ROUNDS],BC); Substitution(a,Si,BC); ShiftRow(a,1,BC); /* ROUNDS-1 ordinary rounds */ for(r = ROUNDS-1; r > 0; r--) { KeyAddition(a,rk[r],BC); InvMixColumn(a,BC); Substitution(a,Si,BC); ShiftRow(a,1,BC); } /* End with the extra key addition */ KeyAddition(a,rk[0],BC); return 0; }
int rijndaelEncryptRound (word8 a[4][MAXBC], int keyBits, int blockBits, word8 rk[MAXROUNDS+1][4][MAXBC], int rounds) /* Encrypt only a certain number of rounds. * Only used in the Intermediate Value Known Answer Test. */ { int r, BC, ROUNDS; switch (blockBits) { case 128: BC = 4; break; case 192: BC = 6; break; case 256: BC = 8; break; default : return (-2); } switch (keyBits >= blockBits ? keyBits : blockBits) { case 128: ROUNDS = 10; break; case 192: ROUNDS = 12; break; case 256: ROUNDS = 14; break; default : return (-3); /* this cannot happen */ } /* make number of rounds sane */ if (rounds > ROUNDS) rounds = ROUNDS; /* begin with a key addition */ KeyAddition(a,rk[0],BC); /* at most ROUNDS-1 ordinary rounds */ for(r = 1; (r <= rounds) && (r < ROUNDS); r++) { Substitution(a,S,BC); ShiftRow(a,0,BC); MixColumn(a,BC); KeyAddition(a,rk[r],BC); } /* if necessary, do the last, special, round: */ if (rounds == ROUNDS) { Substitution(a,S,BC); ShiftRow(a,0,BC); KeyAddition(a,rk[ROUNDS],BC); } return 0; }
void AES128::encrypt16( unsigned char buffer[ 16 ] ) { AddRoundKey( buffer, key_schedule[ 0 ] ); for ( register unsigned short r = 1; r < 10; ++r ) { Substitution( buffer ); ShiftRows( buffer ); MixColumns( buffer ); AddRoundKey( buffer, key_schedule[ r ] ); } Substitution( buffer ); ShiftRows( buffer ); AddRoundKey( buffer, key_schedule[ 10 ] ); }
int _rijndaelEncrypt (word8 a[4][MAXBC], int keyBits, int blockBits, word8 rk[MAXROUNDS+1][4][MAXBC]) { /* Encryption of one block. */ int r, BC, ROUNDS; switch (blockBits) { case 128: BC = 4; break; case 192: BC = 6; break; case 256: BC = 8; break; default : return (-2); } switch (keyBits >= blockBits ? keyBits : blockBits) { case 128: ROUNDS = 10; break; case 192: ROUNDS = 12; break; case 256: ROUNDS = 14; break; default : return (-3); /* this cannot happen */ } /* begin with a key addition */ KeyAddition(a,rk[0],BC); /* ROUNDS-1 ordinary rounds */ for(r = 1; r < ROUNDS; r++) { Substitution(a,S,BC); ShiftRow(a,0,BC); MixColumn(a,BC); KeyAddition(a,rk[r],BC); } /* Last round is special: there is no MixColumn */ Substitution(a,S,BC); ShiftRow(a,0,BC); KeyAddition(a,rk[ROUNDS],BC); return 0; }
int rijndaelDecryptRound (word8 a[4][4], word8 rk[MAXROUNDS+1][4][4], int rounds) /* Decrypt only a certain number of rounds. * Only used in the Intermediate Value Known Answer Test. * Operations rearranged such that the intermediate values * of decryption correspond with the intermediate values * of encryption. */ { int r; /* make number of rounds sane */ if (rounds > ROUNDS) rounds = ROUNDS; /* First the special round: * without InvMixColumn * with extra KeyAddition */ KeyAddition(a,rk[ROUNDS],4); Substitution(a,Si,4); ShiftRow(a,1,4); /* ROUNDS-1 ordinary rounds */ for(r = ROUNDS-1; r > rounds; r--) { KeyAddition(a,rk[r],4); InvMixColumn(a,4); Substitution(a,Si,4); ShiftRow(a,1,4); } if (rounds == 0) { /* End with the extra key addition */ KeyAddition(a,rk[0],4); } return 0; }
void PropertyImpl::setSubstitution(DataFactoryPtr mdg, const char* alias, const Type& substype) { substitutions.push_back(Substitution(mdg,alias,substype)); }
// 敵抽選はBefore_Battle.cppで行う int BattleMgr( Character_t *Character, EnemySelect_t EnemySelect){ MessageFrame(); switch(BattlePhase){ // 初期化 敵の枠に代入 case 0:for(int i=0;i<4;i++){ if(EnemySelect.Enemy[i]!=0)Substitution( &Enemy[i], EnemyStatus[(EnemySelect.Enemy[i]-1)]); if(EnemySelect.Enemy[i]==0)Substitution( &Enemy[i], EnemyStatus[(EnemySelect.Enemy[i]-1)], FALSE); SecondIni( Enemy[i], i); }BattlePhase=1;break; // 戦闘に入ったとこ case 1:if(DrawBattleMessageString( 0, 1, BattleMenuString)==100)BattlePhase=2;break; // 何を行うかの選択 case 2:switch(DrawMenu( 2, 2, KEY_INPUT_Z, BattleMenu )){ case 0:BattlePhase=4;SpeedChecker( Character, Enemy );break; case 1:break; case 2:BattlePhase=3;break; case 3:break; }break; // 逃げる時の文表示 case 3:if( DrawBattleMessageString( 2, 2, BattleMenuString ) == 100 ){BattlePhase=0;MenuSelect=0;return 2;}break; // 攻撃する敵を選択数 case 4:{ switch(MenuSelect){ case 0:{ DrawFormatString(230,380,GetColor(255,255,255),"勇者はどの敵を攻撃する?"); Attack[0]=DrawCursor( Enemy ); if(Attack[0]!=100){ if(Attack[0]!=200)MenuSelect++; BattlePhase=2; } }break; case 1:{ DrawFormatString(230,380,GetColor(255,255,255),"勇者(二人目)どの敵を攻撃する?"); Attack[1]=DrawCursor( Enemy ); if(Attack[1]!=100){ if(Attack[1]==200)BattlePhase=2; else MenuSelect++; } }break; case 2:{MenuSelect=0;BattlePhase=5;}break; } }break; // 攻撃実行 case 5:{ // 敵四体 for(int i=0;i<4;i++){ if( Enemy[i].Speed==Data[BattleTurn] && doing==0 && (Enemy[i].Speed2==0)){ doing=1; if( Enemy[i].Defense && Enemy[i].HP>0){ switch( DrawBattleMessageString( 5, 6, BattleMenuString, Enemy[i].NameNumber, Damage )){ case 0:if(once==0){Rand=GetRand(1);Damage=DamageCalc( Enemy[i], *(Character+Rand) );once++;}break; case 1:if(Rand!=2)(Character+Rand)->HP-=Damage;Rand=2;break; case 100:Enemy[i].Speed2=1;Rand=0;BattleTurn++;once=0;break; } }else if( Enemy[i].HP<=0 ){ BattleTurn++; Enemy[i].Speed2++; Enemy[i].Flag=0; } } } if( !Character->Speed2 && Character->Speed==Data[BattleTurn] && !doing ){ doing=1; if(Enemy[Attack[0]].Flag){ switch( DrawBattleMessageString( 3, 4, BattleMenuString, Enemy[Attack[0]].NameNumber, Damage )){ case 0:if(!once){Damage=DamageCalc( *Character, Enemy[Attack[0]] );once++;}break; case 1:if(Rand!=2)Enemy[Attack[0]].HP-=Damage;Rand=2;break; case 100:Character->Speed2=1;if(Enemy[Attack[0]].HP<=0)Enemy[Attack[0]].Flag=0;Rand=0;BattleTurn++;once=0;break; } }else BattleTurn+=1; } if( !(Character+1)->Speed2 && (Character+1)->Speed==Data[BattleTurn] && !doing){ doing=1; if(Enemy[Attack[1]].Flag){ switch( DrawBattleMessageString( 3, 4, BattleMenuString, Enemy[Attack[1]].NameNumber, Damage )){ case 0:if(once==0){Damage=DamageCalc( *(Character+1), Enemy[Attack[1]] );once++;}break; case 1:if(Rand!=2)Enemy[Attack[1]].HP-=Damage;Rand=2;break; case 100:(Character+1)->Speed2=1;if(Enemy[Attack[1]].HP<=0)Enemy[Attack[1]].Flag=0;Rand=0;BattleTurn++;once=0;break; } }else BattleTurn+=1; } //BattleTurnが6は全員行動したことになっている if( !doing && BattleTurn==6){ doing=1; BattlePhase=2; for(int i=0; i<4; i++ )Enemy[i].Speed2=0; for(int i=0; i<2; i++)(Character+i)->Speed2=0; //敵全滅 if( Enemy[0].HP<=0 && Enemy[1].HP<=0 && Enemy[2].HP<=0 && Enemy[3].HP<=0 ){ for(int i=0 ; i<4; i++){ //先に経験値の合計を求める EnemyExpSum+=Enemy[i].Ex; Substitution( &Enemy[i], EnemyStatus[(EnemySelect.Enemy[i]-1)], FALSE); } BattlePhase=6; } else BattleTurn=0; } }doing=0;break;//case 5の終了 // 戦闘終了後の処理 case 6:{ if( DrawBattleMessageString( 7, 8, BattleMenuString,0,EnemyExpSum ) == 100 ){ doing=0; BattlePhase=0; BattleTurn=0; for(int i=0; i<4; i++ )Enemy[i].Speed2=0; for(int i=0; i<2; i++)(Character+i)->Speed2=0; if(Character->HP>=0)Character->Ex+=EnemyExpSum; // EnemyExpSumは一度の戦闘で手に入れた経験値の合計 EnemyExpSum=0; if(Levelup(Character)==1)BattlePhase=7; else return 2; } }break; // レベルアップ時 case 7:{ if( DrawBattleMessageString( 9, 9, BattleMenuString, 0, Character->LEVEL) == 100 ){ BattlePhase=0; return 2; } }break; }//switchの終了 //数字表示系 敵の数字を表示 DrawFormatString(420,360,GetColor(255,255,255),"BattleTurn:%d",BattleTurn); DrawFormatString(150,100,GetColor(255,255,255),"%d,%d,%d,%d,%d,%d",Data[0],Data[1],Data[2],Data[3],Data[4],Data[5]); DrawFormatString(150,120,GetColor(0,255,0),"%d",Character->Ex); for(int i=0;i<4;i++)DrawFormatString(320,240+20*i,GetColor(255,255,255),"%d",EnemySelect.Enemy[i]); //条件を満たしている敵の枠のみ表示 for(int i=0; i<4; i++)if(Enemy[i].HP>0 && Enemy[i].Flag==1)DrawGraph( Enemy[i].X+80*i, Enemy[i].Y, Enemy[i].Graph, TRUE ); //勇者側のステータス表示 for(int i=0; i<2; i++){ if( (Character+i)->HP > 0 ){ DrawGauge( 15, 16+35*i, (Character+i)->MaxHP, (Character+i)->HP, GetColor( 0, 255, 0 ), GetColor(0, 255/2, 0),TRUE); DrawGauge( 15, 31+35*i, (Character+i)->MaxMP, (Character+i)->MP, GetColor( 255, 255, 0 ),GetColor( 255/2, 255/2, 0 ),TRUE ); }else if( (Character+i)->HP <=0 ) (Character+i)->HP=0; } if(CheckHitKey(KEY_INPUT_H)==1)return 2; return 4; }
static int check_xkeysymdb(Display *display, bool verbose) { if (verbose) { (void) xlibdir(display, verbose); } if (verbose) { std::cout << "Checking for XKeysymDB... "; std::cout.flush(); } String me, my_class; XtGetApplicationNameAndClass(display, &me, &my_class); string xkeysymdb; { const _XtString s = getenv("XKEYSYMDB"); if (s != 0) xkeysymdb = s; } if (xkeysymdb.empty()) { String s = XtResolvePathname(display, "", "XKeysymDB", "", (String)0, Substitution(0), 0, XtFilePredicate(0)); if (s != 0) xkeysymdb = s; XtFree(s); } if (!xkeysymdb.empty()) { if (verbose) { std::cout << xkeysymdb << "\n"; std::cout.flush(); } // Fix it now static string env; env = "XKEYSYMDB=" + xkeysymdb; putenv(CONST_CAST(char*,env.chars())); return 0; // Okay } if (xlibdir(display) != 0) { string path = string(xlibdir(display)) + "/XKeysymDB"; if (is_file(path)) { if (verbose) { std::cout << path << "\n" << "Note: this is not the default path compiled into " << me << ".\n" << " To avoid having " << me << " determine this setting each time it is started,\n" << " please set the XKEYSYMDB " << "environment variable to\n" << " " << quote(path) << ".\n"; std::cout.flush(); } // Fix it static string env; env = "XKEYSYMDB=" + path; putenv(CONST_CAST(char*,env.chars())); return 0; } }
/* Parse a splicing subsitution */ VyParseTree* ParseSpliceSubstitution(){ /* Parse the next item and put it in a substitution node */ return Substitution(Parse(), 1); }