コード例 #1
0
ファイル: Steg.cpp プロジェクト: Xerxes004/steganographizer
/**
 * Retrieves a secret message from the specified BMP. The secret message is
 * stored in an output file if specified, otherwise it is written to the
 * console.
 * 
 * @param courier a BMP image which contains a secret message
 * @param output an optional output text file where the secret message is stored
 */
void Steg::decrypt(const std::string &courier, const std::string output)
{
	std::vector<char> modifiedBytes;
	read(modifiedBytes, courier);
	
	std::string payload = "";
	if (extractPayload(payload, modifiedBytes))
	{	
		if (output == "")
		{
			std::cout << payload << std::endl;
		}
		else
		{
			std::ofstream outFile(output);
			
			if (outFile.is_open() && !outFile.fail())
			{
				outFile.write(payload.c_str(), payload.length());
			}
			else
			{
				throw std::runtime_error("Output file failed to open, abort.");
			}
		}
	}
	else
	{
		std::string msg = "Input image is not encrypted!\n";
		msg += "A non-ASCII character was found.";

		throw std::runtime_error(msg);
	}
}
コード例 #2
0
ファイル: Steg.cpp プロジェクト: Xerxes004/steganographizer
/**
 * Analyzes the a BMP file to allow the user to plan their message length
 * appropriately.
 * 
 * @param image the name of the image to analyze
 */
void Steg::analyze(const std::string &image)
{
	std::vector<char> bytes;
	read(bytes, image);

	const unsigned int dWord = 
		bytes.at(0) << 24 | 
		bytes.at(1) << 16 | 
		bytes.at(2) << 8  | 
		bytes.at(3);
	
	auto header = getHeaderSize(bytes);
	
	unsigned short imageType = 0;

	switch (header)
	{
	case 10:
		imageType = 1;
		break;

	case 16:
		imageType = 2;
		break;

	case 54:
		imageType = 3;
		break;

	case 122:
		imageType = 4;
		break;

	default:
		imageType = -1;
		break;
	}

	std::cout << "  Analyzing \"" << image << "\"" << std::endl;
	std::cout << "    Image size : " << bytes.size() << " bytes\n";
	std::cout << "    Header size: " << header << " bytes" << std::endl;
	std::cout << "    BMP type   : " << imageType << std::endl;
	std::cout << "    Max payload: " 
	          << ((bytes.size() - getHeaderSize(bytes)) / 8) - 1
	          << " characters\n";

    bool encrypted = true;

    std::string payload;
	
	if (!extractPayload(payload, bytes))
	{
    	encrypted = false;
    }

    std::cout << "    This image ";
    
    if (encrypted)
    {
    	std::cout << "may be ";
    }
    else
    {
    	std::cout << "is probably not ";
    }

    std::cout << "encrypted.\n";
}
コード例 #3
0
ファイル: BPTC1969.c プロジェクト: kb1isz/linDmrMaster
struct BPTC1969 decodeBPTC1969(bool bits[264]){

        bool *infoBits; //196 info bits
        bool *deInterleavedBits; //196 bits
        static bool *payloadBits; //96  bits
        int blocksToFollow=0,a;
        unsigned char dpf=0,sap=0,bitPadding=0;
	struct BPTC1969 BPTC1969decode;

        infoBits = extractInfo(bits);
        deInterleavedBits = deInterleave(infoBits);
        payloadBits = extractPayload(deInterleavedBits);

        /*printf("Payload bits\n");
        for(a=0;a<96;a++){
                printf("%i",*(payloadBits+a));
        }
        printf("\n");*/
        if(*(payloadBits+1) == 1){
		BPTC1969decode.responseRequested = true;
		 //syslog(LOG_NOTICE,"response requested"); 
	}
	else{
		BPTC1969decode.responseRequested = false;
		//syslog(LOG_NOTICE,"NO response requested");
	}

        for(a=4;a<8;a++){
                if(*(payloadBits + a) == true) dpf = dpf + (char)(8 / pow(2,a-4));
        }
        //syslog(LOG_NOTICE,"Data Packet Format: ");
	BPTC1969decode.dataPacketFormat = dpf;
        switch (dpf){
                case 0:
                //syslog(LOG_NOTICE,"Unified Data Transport\n");
                break;

                case 1:
                //syslog(LOG_NOTICE,"Response packet\n");
                break;

                case 2:
                //syslog(LOG_NOTICE,"Data packet with unconfirmed delivery\n");
                break;

                case 3:
                //syslog(LOG_NOTICE,"Data packet with confirmed delivery\n");
                break;

                case 13:
                //syslog(LOG_NOTICE,"Short Data: Defined\n");
                break;
                case 14:
                //syslog(LOG_NOTICE,"Short Data: Raw or Status/Precoded\n");
                break;

                case 15:
                //syslog(LOG_NOTICE,"Proprietary Data Packet\n");
                break;

        }

        for(a=8;a<12;a++){
                if(*(payloadBits + a) == true) sap = sap + (char)(8 / pow(2,a-8));
        }
		
	//syslog(LOG_NOTICE,"SAP id: ");
	BPTC1969decode.sapId = sap;
        switch (sap){

                case 0:
                //syslog(LOG_NOTICE,"Unified Data Transport\n");
                break;

                case 2:
                //syslog(LOG_NOTICE,"TCP/IP header compression\n");
                break;

                case 3:
                //syslog(LOG_NOTICE,"UDP/IP header compression\n");
                break;

                case 4:
                //syslog(LOG_NOTICE,"IP based Packet data\n");
                break;

                case 5:
                //syslog(LOG_NOTICE,"Address Resolution Protocol(ARP)\n");
                break;

                case 9:
                //syslog(LOG_NOTICE,"Proprietary Packet data\n");
                break;

                case 10:
                //syslog(LOG_NOTICE,"Short Data\n");
                break;

        }
        if (dpf == 13){
                for(a=12;a<16;a++){//only AB in 2nd octet
                         if(*(payloadBits + a) == true) blocksToFollow = blocksToFollow + (char)(8 / pow(2,a-12));
                }
                BPTC1969decode.appendBlocks = blocksToFollow;
		//syslog(LOG_NOTICE,"Appended blocks : %i\n",blocksToFollow);

                for(a=72;a<80;a++){
                         if(*(payloadBits + a) == true) bitPadding = bitPadding + (char)(128 / pow(2,a-12));
                }
        }

        return BPTC1969decode;
}