Exemplo n.º 1
62
int main()
{
	system("cls");
	do
	{
		// requests prime number from the user.
	printf("Enter a prime number: ");			
	scanf("%d",&ptest);
		// checks if it is prime before assigning it to the 'p' variable.
	flag=prime(ptest);
	}while(flag==0);
	if(flag==1)
	p=ptest;
	do
	{
		// requests another prime number from the user.
	printf("\nEnter a second prime number: ");
	scanf("%d",&qtest);
		// checks if it is prime before assigning it to the 'q' variable.
	flag=prime(qtest);
	}while(flag==0);
	if(flag==1)
	q=qtest;
		// gets the message from the user.
	printf("\nEnter message: ");
	fflush(stdin);
	scanf("%[^\n]%*c",Msg);
	len=strlen(Msg);
	for(i=0;i!=len;i++)
	m[i]=Msg[i];
		// calculates the modulus and phi.
	n=p*q;
	phi=(p-1)*(q-1);
		// then e and d.
	calcE();
	printf("\nPossible values of e and d: ");
	for(i=0;i<j-1;i++)
	printf("\n%ld\t%ld",e[i],d[i]);
	encrypt();
	decrypt();
	getch();
	return(0);
}
Exemplo n.º 2
0
void Test_encrypt::stringUnderThanMatrix()
{
	input=fopen("test.txt","w+");
	char string[50]="Example text for testing this algorithm";
	fwrite((void*)string,1,strlen(string),input);
	fclose(input);

	input=fopen("test.txt","w+");
	output=fopen("result.txt","w+");
	int vector[5]={0,2,4,3,1};
	encrypt(5,8,vector);
	fclose(output);
	fclose(input);

	output=fopen("result.txt","w+");
	fread((void*)string,1,100,output);
	CFIXCC_ASSERT_EQUALS(string,"Elxrttaia  tnighpeos  r\0mtfegsomxet inlt");
	fclose(output);
}
Exemplo n.º 3
0
void Test_encrypt::stringSizeCorrespondDoubleSizeOfMatrix()
{
	input=fopen("test.txt","w+");
	char string[50]="Example text for testing this  algorithm";
	fwrite((void*)string,1,strlen(string),input);
	fclose(input);

	input=fopen("test.txt","w+");
	output=fopen("result.txt","w+");
	int vector[5]={0,2,4,3,1};
	encrypt(5,4,vector);
	fclose(output);
	fclose(input);

	output=fopen("result.txt","w+");
	fread((void*)string,1,100,output);
	CFIXCC_ASSERT_EQUALS(string,"Elxra  tplosmtfexet tt rnilt  omgsgh ihai");
	fclose(output);
}
Exemplo n.º 4
0
void Test_encrypt::emptyString()
{
	input=fopen("test.txt","w+");	
	char string[50]="";
	fwrite((void*)string,1,strlen(string),input);
	fclose(input);

	input=fopen("test.txt","w+");
	output=fopen("result.txt","w+");
	int vector[5]={0,2,4,3,1};
	encrypt(5,8,vector);
	fclose(output);
	fclose(input);

	output=fopen("result.txt","w+");
	fread((void*)string,1,100,output);
	CFIXCC_ASSERT_EQUALS(string,"\0                                       ");
	fclose(output);
}
Exemplo n.º 5
0
cryptor &cryptor::get(char *buf,
                      int max_length,
                      istream &is,
                      int &more,
                      char terminator)
{
  is.get(buf, max_length, terminator);
  if (is.peek() == terminator)
  {
    is.get();
    more = 0;
  }
  else
    more = 1;

  encrypt(buf);

  return *this;
}
int main()
{
	//nb表示分组长度;nk表示密钥长度
	int i,nb,nk;
	char str[]="abcd1234567890123456789012345678901212345678901234567890123456789012";
    char key[32];
	char block[32];
	gentables();
	strtoHex(str,key);
	hextoStr(key,str);
	printf("Key=");
	for (i=0;i<64;i++)
		printf("%c",str[i]);
	printf("\n");
	for (i=0;i<32;i++)
		block[i]=i;
	for (nb=4;nb<=8;nb+=2)
		for (nk=4;nk<=8;nk+=2)
		{
			printf("\nBlock Size= %d bits, Key Size= %d bits\n",nb*32,nk*32);
			gkey(nb,nk,key);
			printf("Plain= ");
			for (i=0;i<nb*4;i++)
				printf("%02x",block[i]);
			printf("\n");
			//进行加密
			encrypt(block);
			//输出密文
			printf("Encrypt= ");
			for (i=0;i<nb*4;i++)
				printf("%02x",(unsigned char)block[i]);
			printf("\n");
			//进行解密
			decrypt(block);
			//输出明文
			printf("Decrypt= ");
			for (i=0;i<nb*4;i++)
				printf("%02x",block[i]);
			printf("\n");
		}
		system("pause");
		return 0;
}
Exemplo n.º 7
0
static inline uint8_t encryptMessage(struct Message* message,
                                     struct Wrapper* wrapper)
{
    assert(message->padding >= 36 || !"not enough padding");

    encrypt(wrapper->nextNonce,
            message,
            wrapper->secret,
            wrapper->isInitiator,
            wrapper->authenticatePackets);

    Message_shift(message, 4);

    union Headers_CryptoAuth* header = (union Headers_CryptoAuth*) message->bytes;
    header->nonce = Endian_hostToBigEndian32(wrapper->nextNonce);
    wrapper->nextNonce++;

    return wrapper->wrappedInterface->sendMessage(message, wrapper->wrappedInterface);
}
Exemplo n.º 8
0
int main() {
	char cxt[512] = {0};
	byte key[] = "hello, worldxxyy";
	byte pt[] = "this is the plaintext";
	byte ct[32] = {0};
	byte pt2[32] = {0};

	aes.set_key(cxt, key, 16);
	encrypt(cxt, pt, sizeof(pt), ct);
	printf("cipher text:\n");
	hexdump(ct, 32);

	decrypt(cxt, ct, 32, pt2);
	printf("decrypted text:\n");
	hexdump(pt2, 32);
	printf("%s\n", pt2);

	return 0;
}
Exemplo n.º 9
0
/**
 * @brief Writes to file associated with the calling object. If a valid key
 *        is available, data is encrypted (AES-GCM) prior to writing.
 *
 * @param ss const reference to a string stream with data.
 * @param key const reference to a byte vector with the encryption key.
 *
 * @return true, if data was sucessfully written to file.
 */
bool FileCryptopp::writeFile(
    const std::stringstream& ss,
    const std::vector<uint8_t>& key
) {

    // Start a file stream.
    std::ofstream fileStream(_filename, std::ios::binary);

    // Check if file stream is open.
    if (!fileStream.is_open()) {
        return false;
    }

    // Initialize an ostream_iterator to write to the file stream.
    std::ostream_iterator<uint8_t> oit(fileStream);

    // Check if encyption key is provided.
    if (!key.empty()) {
        // Check if encryption key has length equal to default AES key length.
        if (key.size() != FileCryptopp::AESNODE_DEFAULT_KEY_LENGTH_BYTES) {
            // Invalid key.
            std::cout << "Invalid key length";
            return false;
        }

        // Vector to store encrypted bytes of data.
        std::vector<uint8_t> cipherData;

        // Attempt to encrypt input stream ss and load bytes into cipherData.
        if (!encrypt(ss, cipherData, key)) {
            // Failed encryption.
            return false;
        }
        // Write encrypted bytes from cipherData to file as chars.
        std::copy(cipherData.begin(), cipherData.end(), oit);
    } else {
        // Write to file without encryption.
        fileStream << ss.str();
    }

    fileStream.close();
	return true;
}
Exemplo n.º 10
0
/*
 * encrypt(keySize,password,original_message,encrypted_message, mode, padding)
 * - encrypts a message using AES Algorithm
 *
 * Parameters:
 *    keySize : Size of key to use in AES Algorithm
 *    password: Key to encrypt plaintext message.
 *    original_message: Plaintext message before calculating AES Algorithm
 *    encrypted_message: Ciphertext message after calculating AES Algorithm
 *    mode: cipher mode, two ways: ECB
 *    padding: padding mode to fill blocks, tree ways PKCS5, ZEROS, X923
 *
 * Examples:
 *  AES.encrypt(128,"libelium","Libelium",encrypted_message,ECB,PKCS5)
 *
 */
uint8_t WaspAES::encrypt(	uint16_t keySize
							, char* password
							, char original_message[]
							, uint8_t* encrypted_message
							, uint8_t mode
							, uint8_t padding)
{
	// Calculate length of the original message
	uint16_t original_length;
	original_length = strlen(original_message);

	return encrypt(	keySize,
					password,
					(uint8_t*) original_message,
					original_length,
					encrypted_message,
					mode,
					padding);	
}
Exemplo n.º 11
0
int main(int argc, string argv[])
{
    //validate command line args
    if (argc != 2)
    {
        printf("You must supply at minimum and at most one command line argument. e.g. ./caeser 4. PLEASE TRY AGAIN!!!!\n");
        return 1;
    }

    //convert string input to int
    int rotateBy = atoi(argv[1]);

    string plainTextMessage = GetString();

    for(int i = 0, len = strlen(plainTextMessage); i < len; i++){
        printf("%c", encrypt(plainTextMessage[i], rotateBy));
    }
    printf("\n");
}
Exemplo n.º 12
0
static TACommandVerdict encrypt_cmd(TAThread thread,TAInputStream stream)

{

    char* block;

    int edflag;

   

    // Prepare

    block=(char*)readPointer(&stream);

    edflag=readInt(&stream);



    START_TARGET_OPERATION(thread);

    errno=0;

    encrypt(block, edflag);

    END_TARGET_OPERATION(thread);



    // Response

    writePointer(thread, block);

    writeInt(thread, errno);



    sendResponse(thread);

    

    return taDefaultVerdict;

}
Exemplo n.º 13
0
void f5star(u8* keyArr, u8* sqn_ak) {
    u8* out5;
    out5 = malloc(16);

    for (i = 0; i < 16; i++) {
        out5[i] = temp[i] ^ opc[i];
    }
    
    convertToBin(out5, binArr);
    rotWord(binArr, 128, 0x08);
    convertToHex(binArr, out5);

    for (i = 0; i < 16; i++) {
        out5[i] ^= c5[i];
    }
    encrypt(out5, keyArr, out5);

    for (i = 0; i < 16; i++) {
        out5[i] ^= opc[i];
    }

    printf("\r\nAK (f5*): ");
    for (i = 0; i < 6; i++) {
        ak[i] = out5[i];
        printf("%02x", ak[i]);
    }
    
    for (i = 0; i < 6; i++) {
        sqn[i] = ak[i] ^ sqn_ak[i];
    }
    
    u8 ind = (sqn[5] & 0b00011111);
    u8 seq = (sqn[5] & 0b11100000);
    ind = (ind + 1) % 32;
    sqn[5] = 0;
    sqn[5] |= ind;
    
    seq += 0b00100000;
    if (seq == 0) {
        sqn[4] += 1;
    }
    sqn[5] |= seq;
}
Exemplo n.º 14
0
void SparkProtocol::variable_value(unsigned char *buf,
                                   unsigned char token,
                                   unsigned char message_id_msb,
                                   unsigned char message_id_lsb,
                                   double return_value)
{
  buf[0] = 0x61; // acknowledgment, one-byte token
  buf[1] = 0x45; // response code 2.05 CONTENT
  buf[2] = message_id_msb;
  buf[3] = message_id_lsb;
  buf[4] = token;
  buf[5] = 0xff; // payload marker

  memcpy(buf + 6, &return_value, 8);

  memset(buf + 14, 2, 2); // PKCS #7 padding

  encrypt(buf, 16);
}
Exemplo n.º 15
0
void main()
{	struct block data,key,temp;
	//unsigned char c1[16]={0x32,0x88,0x31,0xe0,0x43,0x5a,0x31,0x37,0xf6,0x30,0x98,0x07,0xa8,0x8d,0xa2,0x34};
	//unsigned char c2[16]={0x2b,0x28,0xab,0x09,0x7e,0xae,0xf7,0xcf,0x15,0xd2,0x15,0x4f,0x16,0xa6,0x88,0x3c};
	unsigned char c1[16]="Hello World. 123";
	unsigned char c2[16]="My New Password.";	
	int i,j,c=0;
	struct block round_key[11];
	// Initializing Data and Key
	for(i=0;i<4;i++)
	{	for(j=0;j<4;j++)
		{	data.b[i][j]=c1[c];
			key.b[i][j]=c2[c];
			c++;	
		}
	}

	printf("Data and key before encryption:");
	printf("\n Data:\n");
	print_block(data);
	printf("\n Key:\n");
	print_block(key);

	printf("Generating All the round Keys:");
	round_key[0]=key;
	temp=key;	
	for(i=0;i<10;i++)
	{	temp=next_key(temp,i);
		round_key[i+1]=temp;
	}
	printf("All the keys generated.");

	data=encrypt(data,round_key);

	printf("Data after encryption:");
	printf("\n Data:\n");
	print_block(data);

	printf("\nData After Decryption\n");
	data=decrypt(data,round_key);
	print_block(data);
}
Exemplo n.º 16
0
int main(int argc, char* argv[])
{
	if (argc < 2)
	{
		showHelpAndExitWithCode(1);
	}

	// modernize the arguments, because passing arrays is a nightmare
	std::vector<std::string> args(argv, argv + argc);

	try 
	{
		for (int i = 0; i < args.size(); i++)
		{
			if (args.at(i).compare("-e") == 0)
			{
				encrypt(args, i);
				break;
			} 
			if (args.at(i).compare("-d") == 0)
			{
				decrypt(args, i);
				break;
			} 
			if (args.at(i).compare("-a") == 0)
			{
				analyze(args, i);
				break;
			} 
			if (i == args.size() - 1)
			{
				showHelpAndExitWithCode(1);
			}
		}
	}
	catch (std::runtime_error &ex)
	{
		std::cout << ex.what() << std::endl;
	}

	return 0;
}
bool SecureStorage_RemoveItem(const SecureStorageS *storage, const unsigned char *sKey, int16_t keyLen) {
  int16_t saltLen = 0;
  bool ret = false, ret1 = false;
  unsigned char *caEncKey = NULL, *rKey = NULL, *caKey = NULL;
  unsigned char cahKey[SHA256_LEN + UTILS_STR_LEN_SIZE + 1];

  if (storage == NULL || sKey == NULL) {
    snprintf(errStr, sizeof(errStr), "SecureStorage_RemoveItem: Storage and key must not be NULL");
    return false;
  }
  if (keyLen <= 0) {
    snprintf(errStr, sizeof(errStr), "SecureStorage_RemoveItem: key len %d must be positives\n", keyLen);
    return false;
  }
  if (READABLE_STORAGE == true)
    saltLen = 0;
  else if (Utils_GetCharArrayLen(storage->caSalt, &saltLen, KEY_VAL_MIN_STR_LEN, KEY_VAL_MAX_STR_LEN) == false)
    return false;
  if (generateAlignedCharAray(sKey, keyLen, storage->caSalt, saltLen, &caKey) == false) return false;
  if (isLengthValid(caKey, KEY_VAL_MIN_STR_LEN, KEY_VAL_MAX_STR_LEN - 1) == false || getRandomFromKey(storage, caKey, cahKey, &rKey) == false) {
    Utils_Free(caKey);
    return false;
  }
  ret1 = clearKey(storage, cahKey);
  if (ret1 == false) { // continue to try to remove the "real" key value
    snprintf(errStr, sizeof(errStr), "Error: key for random '%s' was not found", cahKey);
  }
  ret = encrypt(caKey, rKey, storage->caSecret, &caEncKey);
  Utils_Free(rKey);
  if (ret == false) {
    Utils_Free(caKey);
    return false;
  }
  if (clearKey(storage, caEncKey) == false) {
    Utils_Free(caEncKey);
    snprintf(errStr, sizeof(errStr), "Error: key '%s' was not found", caKey);
    return false;
  }
  Utils_Free(caKey);
  Utils_Free(caEncKey);
  return ret1;
}
Exemplo n.º 18
0
bool ConnectionFactory::createRemoteConnection(const enum ngsCatalogObjectType type,
                                               const std::string &path,
                                               const Options &options)
{
    switch(type) {
    case CAT_CONTAINER_NGW:
    {
        std::string url = options.asString(KEY_URL);
        if(url.empty()) {
            return errorMessage(_("Missing required option 'url'"));
        }

        std::string login = options.asString(KEY_LOGIN);
        if(login.empty()) {
            login = "******";
        }
        else {
            std::string oldLogin(login);
            login = CPLString(login).Trim();
            if(!compare(oldLogin, login, true)) {
                warningMessage("Login was trimmed!");
            }
        }
        std::string password = options.asString(KEY_PASSWORD);
        bool isGuest = options.asBool(KEY_IS_GUEST);

        CPLJSONDocument connectionFile;
        CPLJSONObject root = connectionFile.GetRoot();
        root.Add(KEY_TYPE, type);
        root.Add(KEY_URL, url);
        root.Add(KEY_LOGIN, login);
        root.Add(KEY_IS_GUEST, isGuest);
        if(!password.empty()) {
            root.Add(KEY_PASSWORD, encrypt(password));
        }

        return connectionFile.Save(path);
    }
    default:
        return errorMessage(_("Unsupported connection type %d"), type);
    }
}
Exemplo n.º 19
0
interface::interface(QWidget *parent)
    : QWidget(parent)
{
    setWindowTitle(tr("Cryptography Course Software"));

    /*create & format*/
    appTabs = new QTabWidget(this);
    appLayout = new QVBoxLayout(this);
    appTitle = new QLabel(tr("<b><font size=5>Convert between Plaintext and ASCII</font></b><br>ASCII is represented in Hex, Integer, or Binary"), this);
    appFooter = new QLabel(tr("Cryptography Course Software<br>Ed Schaefer and Cameron Wong<br>Summer 2011"));
    edPage = new edPageWidget();
    encryptPage = new SAESpageWidget();
    decryptPage = new SAESpageWidget();

    appTabs->addTab(edPage, tr("Encode/Decode"));
    appTabs->addTab(encryptPage, tr("Encrypt"));
    appTabs->addTab(decryptPage, tr("Decrypt"));

    appTitle->setAlignment(Qt::AlignCenter);
    appFooter->setAlignment(Qt::AlignCenter);

    appLayout->addWidget(appTitle);
    appLayout->addWidget(appTabs);
    appLayout->addWidget(appFooter);

    /*initialize*/
    encryptPage->inputL->setTitle(tr("Plaintext"));         //these are the only label differences
    encryptPage->convertButton->setText(tr("Encrypt"));     //between the two SAES widgets; everything
    encryptPage->outputL->setTitle(tr("Ciphertext (Hex)")); //else is reused code

    decryptPage->inputL->setTitle(tr("Ciphertext (Hex)"));
    decryptPage->convertButton->setText(tr("Decrypt"));
    decryptPage->outputL->setTitle(tr("Plaintext"));

    /*signals&slots*/
    connect(appTabs, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
    connect(encryptPage->convertButton, SIGNAL(clicked()), encryptPage, SLOT(encrypt()));   //and make sure the "convert"
    connect(decryptPage->convertButton, SIGNAL(clicked()), decryptPage, SLOT(decrypt()));   //button for each page does the
                                                                                            //correct thing!


}
Exemplo n.º 20
0
void ns_setpassword(User * u, NickCore * nc)
{
    int len = 0;
    char password[PASSCODELEN];

    if (nc->pass)
        free(nc->pass);

    nc->pass = smalloc(PASSMAX);

    /* we'll generate the password just like we
     * did for the passcode */
    generatePassCode(password);

    len = strlen(password);

#ifdef USE_ENCRYPTION
    if (encrypt(password, len, nc->pass, PASSMAX) < 0) {
        alog("%s: Failed to encrypt password for %s (set)", MYNAME,
             nc->display);
        notice_lang(s_NickServ, u, NICK_SET_PASSWORD_FAILED);
        return;
    }

    nc->flags |= NI_ENCRYPTEDPW;
#else
    strncpy(nc->pass, password, PASSMAX);
#endif

    if (do_sendpassword(u, nc, password) != 0)
    {
        alog(LOG_COULDNT_SENDMAIL, MYNAME, nc->display);
	return;
    }

    notice(s_NickServ, u->nick, "Your password has been changed successfully.  Your new password has been e-mailed to you.");

    alog("%s: Password reset for %s (e-mail: %s) by %s!%s@%s.", MYNAME,
         nc->display, nc->email, u->nick, u->username, u->host);

    return;
}
Exemplo n.º 21
0
static int crypto(unsigned char *password, int len, const char *path_passwd, const char *path_key)
{
    int ret = -1;
    char extkey[DATA_SIZE] = {0};
    char clrkey[DATA_SIZE], ecpkey[DATA_SIZE];
    unsigned char m[SHA256_DIGEST_LENGTH];
    
    for(ret = 0; ret < len; ret++) {
        password[ret] |= 0x60;
    }
    printf("crypto path, password: %s, key: %s\n", path_passwd, path_key);
    
    crypto_sha(password, len, m);
    ret = write_bytes(path_passwd, m, SHA256_DIGEST_LENGTH);
    if (ret < 0) {
        printf("write passwd to %s failed\n", path_passwd);
        goto error;
    }
    ret = property_set(PROPERTY_PASSWORD_PATH, path_passwd);
    if (ret < 0) {
        printf("setproperty failed\n");
        goto error;
    }
    
    generate_combo_key(clrkey, DATA_SIZE);
    printf("combo key: %s\n", clrkey);
    encrypt((char *)password, clrkey, strlen(clrkey), ecpkey);
    ret = write_bytes(path_key, (unsigned char*)ecpkey, strlen(clrkey));
    if (ret < 0) {
        printf("write key to %s failed\n", path_key);
        goto error;
    }
    ret = property_set(PROPERTY_KEY_PATH, path_key);
    if (ret < 0) {
        printf("setproperty failed\n");
        goto error;
    }
    
    ret = 0;
error: 
    return ret;
}
Exemplo n.º 22
0
int main(void) {
  FILE *input = fopen( "loop.in", "r" );
  if( input == NULL ) {
    fprintf( stderr, "Could not open loop.in.\n" );
    exit( EXIT_FAILURE );
  }
  char *string = NULL;
  size_t length = getstr( &string, input );
  fclose( input );

  encrypt( string, length );

  FILE *output = fopen( "loop.out", "w" );
  fprintf( output, "%zu\n", length );
  fprintf( output, "%s\n", string );
  fclose( output );

  free( string );
  return 0;
}
Exemplo n.º 23
0
int main(int argc, string argv[])
{   
    // if the user did not include a key in the command line then return an error
    if (argc != 2)
    {
        printf("Usage: ./asciimath key\n");
        return 1;
    }
    
    int key = atoi(argv[1]); 
    string plaintext = GetString();
    
    //  loop to encrypt each character in plaintext 
    for (int i = 0, n = strlen(plaintext); i < n; i++)
        printf("%c", encrypt(key, plaintext[i]));
    
    printf("\n");
        
    return 0;
}
int main(int argc, string argv[])
{
    if (argc == 1) {
        printf("Usage: './vigenere' keyword\n");
        return 1;
    }
    else if (argc == 2) {
        if (check_wordkey(argv[1]) < 0) {
            printf("Wrong argument\n");
            return 1;
        }
        string encrypted_text = encrypt(argv[1]);
        printf("%s\n", encrypted_text);
    }
    else {
        printf("Wrong number of arguments\n");
        return 1;
    }
    return 0;
}
Exemplo n.º 25
0
void Test_encrypt::rowMatrix()
{
	input=fopen("test.txt","w+");
	char string[50]="Example text for testing this  algorithm";
	fwrite((void*)string,1,strlen(string),input);
	fclose(input);
	

	input=fopen("test.txt","w+");
	output=fopen("result.txt","w+");
	int vector[1]={0};
	encrypt(1,40,vector);
	fclose(output);
	fclose(input);

	output=fopen("result.txt","w+");
	fread((void*)string,1,100,output);
	CFIXCC_ASSERT_EQUALS(string,"Example text for testing this  algorithm");
	fclose(output);
}
Exemplo n.º 26
0
void Incident::save(TiXmlDocument* xmlDocument)
{
    std::string data;

    // create incident node
    TiXmlElement* incidentElement = new TiXmlElement( "incident" );
    incidentElement->SetAttribute( "name", _name.c_str() );
    incidentElement->SetAttribute( "location", _locationId );

    // create virtues node        
    TiXmlElement* virtuesElement = new TiXmlElement( "virtues" );
    virtuesElement->SetAttribute( "checksum", checksum( &_virtues, sizeof(Virtues) ) );
    encrypt( data, &_virtues, sizeof(Virtues), _name.c_str() );
    virtuesElement->SetAttribute( "data", data.c_str() );
    incidentElement->InsertEndChild( *virtuesElement );
    delete virtuesElement;

    xmlDocument->InsertEndChild( *incidentElement );
    delete incidentElement;
}
Exemplo n.º 27
0
void Test_encrypt::columnMatrix()
{
	input=fopen("test.txt","w+");
	char string[50]="Exam";
	fwrite((void*)string,1,strlen(string),input);
	fclose(input);
	

	input=fopen("test.txt","w+");
	output=fopen("result.txt","w+");
	int vector[4]={0,3,2,1};
	encrypt(4,1,vector);
	fclose(output);
	fclose(input);

	output=fopen("result.txt","w+");
	fread((void*)string,1,100,output);
	CFIXCC_ASSERT_EQUALS(string,"Emax");
	fclose(output);
}
Exemplo n.º 28
0
long get_limit()
{
	FILE* fp =	fopen(LIMIT_FILEPATH, "rb");
	if(NULL == fp)
	{
		printf("get limit : open tipslimit file failed\n");
		return -1;
	}
	char encrypted_text[BUF_LEN] = {0};
	fread(encrypted_text, BUF_LEN,1,fp);
	fclose(fp);
//	printf("Encrypted text is:%s\n", encrypted_text);
	char* pass = PASS;
	char* decrypted_text = encrypt(encrypted_text, pass);
//	printf("Decrypted text is:%s\n", decrypted_text);
	long num = atol(decrypted_text);
	free(decrypted_text);
	printf("get connection limit : %ld\n", num);
	return num;
}
Exemplo n.º 29
0
void Test_encrypt::matrixSize1()
{
	input=fopen("test.txt","w+");
	char string[50]="E";
	fwrite((void*)string,1,strlen(string),input);
	fclose(input);
	

	input=fopen("test.txt","w+");
	output=fopen("result.txt","w+");
	int vector[1]={0};
	encrypt(1,1,vector);
	fclose(output);
	fclose(input);

	output=fopen("result.txt","w+");
	fread((void*)string,1,100,output);
	CFIXCC_ASSERT_EQUALS(string,"E");
	fclose(output);
}
Exemplo n.º 30
0
void test_encrypt_preformance(unsigned char *plaintext, unsigned char *key, unsigned char *iv)
{
    /* Buffer for ciphertext. Ensure the buffer is long enough for the
     * ciphertext which may be longer than the plaintext, dependant on the
     * algorithm and mode
     */
    unsigned char ciphertext[1024];

    clock_t start = clock();
    double elapsedTime = 0.0;
    int runTimes = 0;
    while (runTimes < 1600000) {
        ++runTimes;

        /* Encrypt the plaintext */
        encrypt(plaintext, static_cast<int>(strlen((char *)plaintext)), key, iv, ciphertext);
    }
    elapsedTime = static_cast<double>(clock() - start) /CLOCKS_PER_SEC;
    std::cout << "Encrypt total run times: " << runTimes << " elapsed Time: " << elapsedTime << "s.\n\n" << std::endl;
}