int main (int argc, char **argv) { int32_t i = 0; struct message msg; msg.size = 0; memset(msg.coded, '\0', sizeof msg.coded); memset(msg.original, '\0', sizeof msg.coded); printf("%s\n\t%s\n\t%s\n\n%s", "Welcome to DC612 1-Day Event", "Crypto Lvl 1", "What type of cipher is this, and what are the keys?", "Input: "); fflush(stdout); if (!fgets(msg.original, sizeof msg.original, stdin)) { printf("%s\n", "You need some from of input."); exit(1); } msg.original[sizeof msg.original - 1] = '\0'; for (i=0; i<strlen(msg.original); i++) { if (strchr(CIPHER_SPECIAL_CHARS, msg.original[i])!=NULL) msg.coded[i] = msg.original[i]; else if (islower(msg.original[i])) msg.coded[i] = TO_CHAR((((int)(msg.original[i]-'a') + LOW_SHIFT) % NUMBER_OF_LETTERS) + 'a'); else if (isupper(msg.original[i])) msg.coded[i] = TO_CHAR((((int)(msg.original[i]-'A') + HIGH_SHIFT) % NUMBER_OF_LETTERS) + 'A'); else if (isdigit(msg.original[i])) msg.coded[i] = TO_CHAR(((int)(msg.original[i]-'0') + DEC_SHIFT) % NUMBER_OF_DIGITS + '0'); else { msg.original[i] = '\0'; msg.coded[i] = '\0'; break; } } msg.coded[sizeof msg.coded - 1] = '\0'; printf("%s %s - ","Plaintext:", msg.original); for (i=0; i<strlen(msg.original); i++) printf("\\%d", msg.original[i]); printf("\n"); printf("%s %s - ", "Ciphertext:", msg.coded); for (i=0; i<strlen(msg.coded); i++) printf("\\%d", msg.coded[i]); printf("\n"); exit(0); }
wi_status wi_parse_length(wi_t self, const char *buf, size_t *to_length) { if (!buf || !to_length) { return WI_ERROR; } *to_length = ( ((((unsigned char) buf[0]) & 0xFF) << 24) | ((((unsigned char) buf[1]) & 0xFF) << 16) | ((((unsigned char) buf[2]) & 0xFF) << 8) | (((unsigned char) buf[3]) & 0xFF)); if (MAX_BODY_LENGTH > 0 && *to_length > MAX_BODY_LENGTH) { #define TO_CHAR(c) ((c) >= ' ' && (c) < '~' ? (c) : '.') return self->on_error(self, "Invalid packet header " "0x%x%x%x%x == %c%c%c%c == %zd", buf[0], buf[1], buf[2], buf[3], TO_CHAR(buf[0]), TO_CHAR(buf[1]), TO_CHAR(buf[2]), TO_CHAR(buf[3]), *to_length); } return WI_SUCCESS; }
int Encodings::toBytes(int encoding, wchar wc, byte *dest){ if (encoding < -6 || encoding == -1 || encoding >= encNamesNum) throw UnsupportedEncodingException(SString(encoding)); if (encoding >= 0){ dest[0] = TO_CHAR(encoding, wc); return 1; }; if (encoding == ENC_UTF8){ int dpos = 0; if (wc <= 0x7F){ dest[dpos] = wc & 0x7F; }; if (wc > 0x7F && wc <= 0x7FF){ dest[dpos] = 0xC0 + (wc>>6); dpos++; dest[dpos] = 0x80 + (wc&0x3F); };