0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

毎日C言語 1日目 暗号解読

Last updated at Posted at 2020-06-20

今日からアルゴリズムを勉強していこうと思う。選ばれたのはC言語です。理由は単純で今勉強中だから。メモ用として使っていくので詳しい解説はしない(というか知識がないからできない)。よく参考書にあるような数字の計算から始めるわけではないのでそこは理解していただきたい。では早速やっていこう。

環境構築に関しては以下の記事を参考にして構築した。(Windows)
※Macはわかりませんので各自で調べてください。
https://webkaru.net/clang/mingw-gcc-environments/

使用している書籍:C言語によるはじめてのアルゴリズム入門
著者:河西朝雄

暗号解読

code.c
# include<stdio.h>

int main(void){
    static char table[] = {'D','B','M','C','U','V','W','X','Y','Z','N','L','A','E','I','T','S','J','H','F','G','K','O','P','R','Q','?'};

    // char型のポインタ変数を定義
    char *p,*str="DWAN";

    // テーブルのインデックスを参照する際に使用
    int index;

    // ポインタ変数('str')に代入されている文字列('ASDF')をポインタ変数(p)に代入
    p = str; 

    // 配列の最後(\0)までループさせる
    while(*p != '\0'){

        // アスキーコードで条件分岐
        if('A' <= *p && *p <= 'Z'){
            index = *p - 'A';
        }else{
            index = 26;
        }
        putchar(table[index]);
        p++;
    }
}

まとめ

初日はこんな感じで終わります。だんだん簡単なことはコメントをしないようにしていきます。

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?