Skip to content

Instantly share code, notes, and snippets.

@alphaKAI
Created January 8, 2013 07:31
Show Gist options
  • Select an option

  • Save alphaKAI/4481971 to your computer and use it in GitHub Desktop.

Select an option

Save alphaKAI/4481971 to your computer and use it in GitHub Desktop.
簡易base64エンコーダ/デコーダ Sugarlessライブラリ http://ishibasystems.ikaduchi.com/downloads/d_8/main.html 使用
#include <stdio.h>
#include "base64.h"
#include "sdim.h"
//Sugarlessライブラリ 著作者 石橋祥太 / 藤代晴嵐   使用
#define VER 01
void pf(void);
int main(int argc, char *argv[]){
int num;
int sum;
char *str;
char *ind;
int i;
if(argc==1){
pf();
return 1;
}
if(argc<=2){
if(strcmp(argv[1],"--help")==0 && argc!=2 || strcmp(argv[1],"-v")==0 && argc!=2){
sum=1;
}
if(strcmp(argv[1],"-e")!=0 && strcmp(argv[1],"-d")!=0 && strcmp(argv[1],"-v")!=0 && strcmp(argv[1],"--help")!=0){
sum=2;
}
//-v
if(strcmp(argv[1],"-v")==0){
printf("Ver.0.0%d\n", VER);
return 0;
}
}
if(argc!=3){
if(strcmp(argv[1],"-e")==0 || strcmp(argv[1],"-d")==0){
sum=2;
}
if(argc!=0 && sum==1){
printf("引数の数が不正です\n");
}
else if(argc!=0 && sum==2){
printf("オプションが不正です\n");
}
pf();
printf("終了します\n");
return argc;
}
else{
if(strcmp(argv[1],"-e")==0){
str=c2b(argv[2], strlen(argv[2]), 0);
num=1;
}
else if(strcmp(argv[1],"-d")==0){
str=b2c(argv[2]);
if(str==NULL){
printf("文字列のデコードに失敗しました\n");
return 3;
}
num=2;
}
//ステータス
switch(num){
case 1:
ind="Encode";
break;
case 2:
ind="Decode";
break;
}
printf("INPUT STRING:%s\n", argv[2]);
printf("MODE:%s\n", ind);
printf("RESULT:%s\n", str);
free(str);
}
printf("COMPLETE\n");
return 0;
}
void pf(void){
printf("簡易base64エンコーダ/デコーダ VER:0.0%d\n", VER);
printf("作者:α改\n\n");
printf("使用方法:\n");
printf("base64 [Option] [String]\n");
printf("[Option]:\n");
printf("-e : 文字列/ファイルのエンコード\n");
printf("-d : 文字列/ファイルのデコード\n");
printf("--help : 使い方表示(現在の出力と同じです)\n");
printf("-v : バージョン情報\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment