Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <assert.h>
- #include <unistd.h>
- int loccc(char *s, int n){
- div_t qr;
- int pos;
- if(n == 0) return 0;
- qr = div(n, 10);
- pos = loccc(s, qr.quot);
- s[pos] = qr.rem + '0';
- return pos + 1;
- }
- int crypt(char* filename){
- FILE *fp;
- FILE *fp2;
- int i;
- int sz;
- unsigned char k[500];
- int cc=2;
- unsigned char c[500]="";
- fp=fopen(filename, "r");
- fread(k, 500, 1, fp);
- fseek(fp, 0L, SEEK_END);
- sz = ftell(fp);
- fp2=fopen(filename, "w+");
- for (i=0; i<sz; i++){
- cc+=(cc^(i+3));
- c[i] = (k[i]+i) ^ (cc+i);
- }
- fwrite(c, 1, strlen(c)/1, fp2);
- fclose(fp);
- fclose(fp2);
- }
- char *str_replace(char *orig, char *rep, char *with) {
- char *result;
- char *ins;
- char *tmp;
- int len_rep;
- int len_with;
- int len_front;
- int count;
- if (!orig || !rep)
- return NULL;
- len_rep = strlen(rep);
- if (len_rep == 0)
- return NULL;
- if (!with)
- with = "";
- len_with = strlen(with);
- ins = orig;
- for (count = 0; tmp = strstr(ins, rep); ++count) {
- ins = tmp + len_rep;
- }
- tmp = result = malloc(strlen(orig) + (len_with - len_rep) * count + 1);
- if (!result)
- return NULL;
- while (count--) {
- ins = strstr(orig, rep);
- len_front = ins - orig;
- tmp = strncpy(tmp, orig, len_front) + len_front;
- tmp = strcpy(tmp, with) + len_with;
- orig += len_front + len_rep;
- }
- strcpy(tmp, orig);
- return result;
- }
- char** str_split(char* a_str, const char a_delim)
- {
- char** result = 0;
- size_t count = 0;
- char* tmp = a_str;
- char* last_comma = 0;
- char delim[2];
- delim[0] = a_delim;
- delim[1] = 0;
- while (*tmp)
- {
- if (a_delim == *tmp)
- {
- count++;
- last_comma = tmp;
- }
- tmp++;
- }
- count += last_comma < (a_str + strlen(a_str) - 1);
- count++;
- result = malloc(sizeof(char*) * count);
- if (result)
- {
- size_t idx = 0;
- char* token = strtok(a_str, delim);
- while (token)
- {
- assert(idx < count);
- *(result + idx++) = strdup(token);
- token = strtok(0, delim);
- }
- assert(idx == count - 1);
- *(result + idx) = 0;
- }
- return result;
- }
- char* ctyhh(char *output_buff, int num){
- char *p = output_buff;
- if(num < 0){
- *p++ = '-';
- num *= -1;
- } else if(num == 0)
- *p++ = '0';
- p[loccc(p, num)]='\0';
- return output_buff;
- }
- int main(int argc, char const *argv[])
- {
- char *what=malloc(500);
- here:
- printf("\nwhat you want to do ? ");
- fgets(what, 500, stdin);
- what[strlen (what) - 1] = '\0';
- if(!strcmp("help",what)){
- printf("\nyou can encrypt file by : encrypt filename\n");
- goto here;
- }else if(!strcmp("decrypt flag",what)){
- printf("\nreally ? do u really think i'm fu**ing stupid ! :(\n");
- goto here;
- }else if(strstr(what, "encrypt")!=NULL){
- what = str_replace(what,"encrypt ","");
- if(access(what,F_OK)!=-1) {
- crypt(what);
- printf("\ndone.\n");
- } else {
- printf("\nFile not found !\n");
- }
- goto here;
- }else if(strstr(what, "quit")!=NULL){
- return 0;
- }else{
- printf("\nuse : help to help :)\nor quit to quit ;)\n");
- goto here;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement