Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
S

saiyuk6 7

@saiyuk6 7
About
Posts
17
Topics
4
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Plugin Abstract Interface idea
    S saiyuk6 7

    ya i know, it was a copy and paste from the first function. it was just something a small test

    C / C++ / MFC question performance help tutorial announcement

  • Plugin Abstract Interface idea
    S saiyuk6 7

    I shall take a look at the Polymorphism, i had planned on eventually making a large class factory. I wanted to implement a hash library. example

    class IHashAlgo {
    public:
    virtual void Init() = 0;
    virtual void Update(PBYTE pData, INT nLength) = 0;
    virtual void Final() = 0;
    virtual void GetResults(PBYTE pData) = 0;
    };

    Abstract Class 1, would be MD5, the results would be the digest Abstract Class 2, would be SHA1 ..... etc I wanted to make a cleaner class library because it got really ugly when i was doing this I hope you understand what i am trying to describe at least

    class CHashAlgo {
    public:
    void Init(INT nType) {
    m_Type = nType;
    switch (nType) {
    case HASHTYPE_MD5:
    MD5Init(&m_md5);
    break;
    case HASHTYPE_SHA1:
    SHA1Init(&m_sha1);
    break;
    default:
    break;
    }
    }
    void Update(PBYTE pData, INT nLength) {
    switch (nType) {
    case HASHTYPE_MD5:
    MD5Update(&m_md5, pData, nLength);
    break;
    case HASHTYPE_SHA1:
    SHA1Update(&m_sha1, pData, nLength);
    break;
    default:
    break;
    }
    }
    void Final() {
    switch (nType) {
    case HASHTYPE_MD5:
    MD5Final(&m_md5);
    break;
    case HASHTYPE_SHA1:
    SHA1Final(&m_sha1);
    break;
    default:
    break;
    }
    }
    void GetResults(PBYTE pData) {
    switch (nType) {
    case HASHTYPE_MD5:
    memcpy(pData, m_md5.digest, MD5_DIGEST_SIZE);
    break;
    case HASHTYPE_SHA1:
    memcpy(pData, m_sha1.digest, SHA1_DIGEST_SIZE);
    break;
    default:
    break;
    }
    }
    int m_Type;
    MD5_CONTEXT m_md5;
    SHA1_CONTEXT m_sha1;
    };

    C / C++ / MFC question performance help tutorial announcement

  • Plugin Abstract Interface idea
    S saiyuk6 7

    I took your advice. Hopefully i executed it correctly, here is the updated snippet. I still use CPluginObject template with the std::shared_ptr implementation because it looks better to type CPluginObject<num> than CreatePluginClass(num, classPtr) or would this be bad development schematics?

    typedef std::shared_ptr<IPlugin> IPluginPtr;

    void CreatePluginClass(int iid, IPluginPtr &pObj)
    {
    if (iid == PLUGIN_CLASS_1)
    pObj = IPluginPtr(new TestPlugin1());
    if (iid == PLUGIN_CLASS_2)
    pObj = IPluginPtr(new TestPlugin2());
    }

    template<int N>
    class CPluginObject {
    public:
    CPluginObject() {
    CreatePluginClass(N, pPluginObj);
    }
    IPluginPtr GrabObject() {
    return std::dynamic_pointer_cast<IPlugin>(pPluginObj);
    }
    protected:
    IPluginPtr pPluginObj;
    };

    void main(void)
    {
    CPluginObject<PLUGIN_CLASS_1> plugin;
    IPluginPtr pObj = plugin.GrabObject();

       pObj->Function1();
       pObj->Function2();
    

    }

    Eventually i want to use std::map so i dont always have to create pObj for calling other classes.

    IPluginPtr GrabObject(std::string strImp)
    {
    if (m_ClassManager.count[strImp])
    return std::dynamic_pointer_cast<IPlugin>(m_ClassManager[strImp]);
    }

    and to call the class

    GrabObject("TestClass1")->Function1();
    GrabObject("TestClass1")->Function2();

    well something in the sorts of this

    modified on Sunday, August 1, 2010 2:58 PM

    C / C++ / MFC question performance help tutorial announcement

  • Plugin Abstract Interface idea
    S saiyuk6 7

    I have a question i want to create a plugin manager, and i have a small example test-bed written. It has abstract classes. The function CreatePluginClass will the main function to control a set of mini classes that will use the same Interface IPlugin and create a Pointer stored into memory for the new class that will eventually have to be released, so i made a auto/release type template class to do that for me CPluginObject as you can see in the example entry main function Will this be reliable, because i kinda want to go through this type of approach and if something wrong with this can someone help me point out what it could be?, so far everything is fine that i can see but im not sure that later on that it will cause me problems, if anyone has done anything like this before. I would appreciate the helpful tips when i tested it i get the results im looking for i guess in the console output shows TestPlugin2::Function1 TestPlugin2::Function1

    #include <stdio.h>

    class IPlugin {
    public:
    virtual void Function1() = 0;
    virtual void Function2() = 0;
    };

    class TestPlugin1 : public IPlugin {
    public:
    virtual void Function1() {
    printf("TestPlugin1::Function1\n");
    }

    virtual void Function2() {
    printf("TestPlugin1::Function1\n");
    }
    };

    class TestPlugin2 : public IPlugin {
    public:
    virtual void Function1() {
    printf("TestPlugin2::Function1\n");
    }

    virtual void Function2() {
    printf("TestPlugin2::Function1\n");
    }
    };

    #define PLUGIN_CLASS_1 100
    #define PLUGIN_CLASS_2 100

    void CreatePluginClass(int iid, IPlugin **pObj)
    {
    *pObj = NULL;
    if (iid == PLUGIN_CLASS_1)
    *pObj = new TestPlugin1();
    if (iid == PLUGIN_CLASS_2)
    *pObj = new TestPlugin2();
    }

    template<int N>
    class CPluginObject {
    public:
    CPluginObject() {
    CreatePluginClass(N, &pPluginObj);
    }
    ~CPluginObject() {
    if (pPluginObj != NULL)
    delete pPluginObj;
    pPluginObj = NULL;
    }

    IPlugin *GrabObject() const {
    return pPluginObj;
    }
    protected:
    IPlugin *pPluginObj;
    };

    void main(void)
    {
    CPluginObject<PLUGIN_CLASS_1> plugin;
    IPlugin *pObj = plugin.GrabObject();

       pObj->Function1();
       pObj->Function2();
    

    }

    modified on Sunday, August 1, 2010 5:36 AM

    C / C++ / MFC question performance help tutorial announcement

  • Hacked Hotmail
    S saiyuk6 7

    well KeePass allows you to use external Key Files, it gives you several options how you want to protect it, just like True Crypt difference between KeePass and TruCrypt is, keepass is just a password database, and TruCrypt allows you to create mini or hdd images, or convert a partition into a protected hdd etc..

    The Lounge question tutorial

  • calculating bytes per second
    S saiyuk6 7

    well i've tried doing that but i get this error

    bm.cpp
    bm.cpp(40) : error C2057: expected constant expression
    bm.cpp(40) : error C2466: cannot allocate an array of constant size 0
    bm.cpp(40) : error C2133: 'bzBuffer' : unknown size

    Well i had started to allocate memory for it because later on i was going to start using a hash driver that i was going to make that would provide me with several hash algo's,.... example there might be errors below, but its just a example of what i had planned to do

    unsigned char *bzBuffer;
    for (int i = HT_MD5; i < (HT_WHIRLPOOL + 1); i++) {
    hash.Init(i);
    bzBuffer = new unsigned char[hash.DigestSize()];
    if (bzBuffer == NULL) {
    //err code here
    return 0;
    }
    hash.Update(hashTest[i].buffer, hashTest[i].length);
    hash.Final(bzBuffer);
    for (int h = 0; h < hash.DigestSize(); h++)
    printf("%02.2%", bzBuffer[i]);
    delete bzBuffer;
    }

    modified on Tuesday, July 20, 2010 12:28 PM

    C / C++ / MFC c++ com debugging performance

  • calculating bytes per second
    S saiyuk6 7

    I've updated the code somewhat now, i have taken your advice by dividing the timers freq i've changed how the bps is calculated as well double bps = (double)((ulSize * iPasses) / tm.Seconds()); i've multiplied the Size of the Buffer by the number of passes that runs in the for loop results are DEBUG: 1074556249.047 Byte/s MEMSET: 0.00/sec 0.98/ms 1.00 GB/sec RESULT: 6.91/sec 6905.56/ms 72.41 MB/sec

    class CTimer {
    public:
    CTimer() {
    m_TimeStart.QuadPart = 0;
    m_TimeStop.QuadPart = 0;
    QueryPerformanceFrequency(&m_Frequency);
    }

    void Start(void) {
    QueryPerformanceCounter(&m_TimeStart);
    }

    void Stop(void) {
    QueryPerformanceCounter(&m_TimeStop);
    }

    double Seconds() const {
    return (double)(m_TimeStop.QuadPart - m_TimeStart.QuadPart) / (double)m_Frequency.QuadPart;;
    }

    double Milliseconds() const {
    return Seconds() * 1000.0;
    }

    private:
    double m_dbFreq;
    LARGE_INTEGER m_Frequency;
    LARGE_INTEGER m_TimeStart;
    LARGE_INTEGER m_TimeStop;
    };

    #define MUL_BYTES 1024.0
    #define MUL_KB (MUL_BYTES*1024.0)
    #define MUL_MB (MUL_KB*1024.0)
    #define MUL_GB (MUL_MB*1024.0)

    std::string BPStoString(double dbPerSec)
    {
    char *pTemp[] = {
    "Bytes", "KB", "MB",
    "GB", "TB", "PB",
    "EB", "ZB", "YB"
    };
    char szTemp[30];

    int i = 0;
    while (dbPerSec >= 0.9 * MUL_BYTES) {
    dbPerSec /= MUL_BYTES;
    i++;
    }

    sprintf(szTemp, "%5.2f %s/sec", dbPerSec, pTemp[i]);
    return std::string(szTemp);
    }

    void Benchmark_MD5(void)
    {
    CTimer tm;

    tm.Start();
    unsigned long ulSize = MUL_KB;
    unsigned char *bzBuffer = new unsigned char[ulSize];
    if (bzBuffer != NULL) {
    memset(bzBuffer, 0, ulSize);
    tm.Stop();
    double bps = (double)((ulSize * 1) / tm.Seconds());
    printf("DEBUG: %5.3f Byte/s\n", bps);
    printf("MEMSET: %5.2f/sec %5.2f/ms %s\n", tm.Seconds(), tm.Milliseconds(),BPStoString(bps).c_str());
    }

    tm.Start();

    MD5_CTX md5;
    int iPasses = 500;
    for (int i = 0; i < iPasses; i++) {
    MD5Init(&md5);
    MD5Update(&md5, bzBuffer, ulSize);
    MD5Final(&md5);
    }
    tm.Stop();
    double bps = (double)((ulSize * iPasses) / tm.Seconds());
    printf("RESULT: %5.2f/sec %5.2f/ms %s\n", tm.Seconds(), tm.Milliseconds(),BPStoString(bps).c_str());

    delete bzBuffer;
    }

    C / C++ / MFC c++ com debugging performance

  • calculating bytes per second
    S saiyuk6 7

    This is the results

    DEBUG: [Passes = 5000] 311191.953 Byte/s
    RESULT: 303.90 KB/sec

    DEBUG: [Passes = 5000] 734956.927 Byte/s
    RESULT: 717.73 KB/sec

    DEBUG: [Passes = 5000] 391962.053 Byte/s
    RESULT: 382.78 KB/sec

    DEBUG: [Passes = 5000] 274082.350 Byte/s
    RESULT: 267.66 KB/sec

    DEBUG: [Passes = 5000] 281520.063 Byte/s
    RESULT: 274.92 KB/sec

    C / C++ / MFC c++ com debugging performance

  • calculating bytes per second
    S saiyuk6 7

    My questions is, im trying to make a small benchmark and im not sure if i am correctly doing this. I am using a high-resolution performance counter, ive placed it in bold This uses MD5, which you can simply get it at http://www.evenbalance.com/downloads/pbmd5.cpp[^] im not really sure if im getting the correct bytes per second

    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include "md5.h"

    #define MUL_BYTES 1024
    #define MUL_KB (MUL_BYTES*1024)
    #define MUL_MB (MUL_KB*1024)

    void Benchmark_MD5(void)
    {
    unsigned __int64 iPerf;
    unsigned __int64 iBaseTime;
    double dbFreq;

    unsigned char bzBuffer[] = {0x0a, 0x55, 0x23};
    unsigned __int64 iValue;

    MD5_CTX md5;
    int iPasses = 5000;

    QueryPerformanceFrequency((LARGE_INTEGER *)&iPerf);
    dbFreq = 1.0 / (double)iPerf;
    QueryPerformanceCounter((LARGE_INTEGER *)&iBaseTime);

    for (int i = 0; i < iPasses; i++) {
    MD5Init(&md5, 0);
    MD5Update(&md5, bzBuffer, 3);
    MD5Final(&md5);
    }

    //16 is for the length of the MD5 Digest added by the passes we tested
    //then divided by the Seconds it took to run

    QueryPerformanceCounter((LARGE_INTEGER *)&iValue);
    double seconds = ((double)(iValue - iBaseTime) * dbFreq);
    double bps = (double)((double)(16 + iPasses) / seconds);

    printf("DEBUG: [Passes = %d] %5.3f Byte/s\n", iPasses, bps);

    printf("RESULT:\t");
    if (bps < MUL_BYTES)
    printf(" %5.2f Bytes/sec\n", bps);
    else if (bps < MUL_KB)
    printf(" %5.2f KB/sec\n", bps / 1024);
    else if (bps < MUL_MB)
    printf(" %5.2f MB/sec\n", bps / 1024 / 1024);
    else
    printf(" %5.2f GB/sec\n", bps / 1024 / 1024 / 1024);
    }

    void main(void)
    {
    Benchmark_MD5();
    }

    C / C++ / MFC c++ com debugging performance

  • Hacked Hotmail
    S saiyuk6 7

    you could use TrueCrypt to store your passwords, and generate a password using SHA256/8 = 32 (Digest Size) * 2 = 64 Characters in HEX string. because TrueCrypt max password string is 64 length, but you can also use a Keyfile this generates a pretty strong password, and if anything you could replace a few characters with symbols it SHA256 ^ MD5 +=2 Stepping

    #include <stdio.h>
    #include <string.h>
    #include "sha2.h"
    #include "md5.h"

    void Password_Create(char *pPass)
    {
    sha256_ctx sha256;
    MD5_CTX md5;
    unsigned char bzDigest[SHA256_DIGEST_SIZE];
    int iSize = strlen(pPass);

    MD5Init(&md5);
    sha256_init(&sha256);

    MD5Update(&md5, (unsigned char*)pPass, iSize);
    sha256_update(&sha256, (unsigned char*)pPass, iSize);

    MD5Final(&md5);
    sha256_final(&sha256, bzDigest);

    for (int i = 0; i < 64; i += 2)
    bzDigest[i/2] ^= md5.digest[i/4];

    printf("\nSHA256^MD5 : ");

    for (int i = 0; i < 32; i ++)
    printf("%02.2X", bzDigest[i]);
    }

    int main(int argc, char *argv[])
    {
    if (argc > 1)
    Password_Create(argv[1]);
    }

    There is also a program called KeePass which is pretty good as well, it can help generate pretty strong passwords Im not sure what the maximum length for Hotmail passwords are, if anything you can copy/splice the results hope that helps

    The Lounge question tutorial

  • proper conversion of unsigned char [16] -> unsigned long [4] [modified]
    S saiyuk6 7

    i fixed it, thank you very much for your help, i noticed

    if (tl->_1 == pBuffer[0] && tl->_2 == pBuffer[1] &&
    tl->_3 == pBuffer[2] && tl->_4 == pBuffer[4])
    bResult = true;

    pBuffer[4] should of been pBuffer[3] i was going out of range of the array which didnt exist here is the updated code

    int _ustrlen(unsigned char *pbz)
    {
    const unsigned char *ptr;
    for (ptr = pbz; *ptr; ++ptr);
    return (ptr - pbz);
    }

    void SignBuffer(unsigned char *pbzKey, unsigned char *pbzBuffer,
    unsigned int iSize, unsigned long *pSignature)
    {
    MD5_CTX md5, md5key;
    BLOWFISH_CTX bf;

    MD5Init(&md5);
    MD5Update(&md5, pbzBuffer, iSize);
    MD5Final(&md5);

    _2LONG *tl = (_2LONG*) md5.digest;

    printf("BLE 1\t\t %x %x %x %x\n", tl->_1, tl->_2, tl->_3, tl->_4);

    MD5Init(&md5key);
    MD5Update(&md5key, pbzKey, _ustrlen(pbzKey));
    MD5Final(&md5key);

    Blowfish_Init(&bf, md5key.digest, 16);
    Blowfish_Encrypt(&bf, &tl->_1, &tl->_2);
    Blowfish_Encrypt(&bf, &tl->_3, &tl->_4);

    pSignature[0] = tl->_1;
    pSignature[1] = tl->_2;
    pSignature[2] = tl->_3;
    pSignature[3] = tl->_4;

    printf("BLE 2\t\t %x %x %x %x\n", pSignature[0], pSignature[1],
    pSignature[2], pSignature[3]);
    }

    bool VerifyBuffer(unsigned char *pbzKey, unsigned char *pSignature,
    unsigned int iSize, unsigned long *pBuffer)
    {
    BLOWFISH_CTX bf;
    MD5_CTX md5, md5key;
    bool bResult = false;

    printf("BLD 1\t\t %x %x %x %x\n", pBuffer[0], pBuffer[1],
    pBuffer[2], pBuffer[3]);

    MD5Init(&md5key);
    MD5Update(&md5key, pbzKey, _ustrlen(pbzKey));
    MD5Final(&md5key);

    Blowfish_Init(&bf, md5key.digest, 16);
    Blowfish_Decrypt(&bf, &pBuffer[0], &pBuffer[1]);
    Blowfish_Decrypt(&bf, &pBuffer[2], &pBuffer[3]);

    printf("BLD 2\t\t %x %x %x %x\n", pBuffer[0], pBuffer[1],
    pBuffer[2], pBuffer[3]);

    MD5Init(&md5);
    MD5Update(&md5, pSignature, iSize);
    MD5Final(&md5);

    _2LONG *tl = (_2LONG*) md5.digest;
    printf("BLD 3\t\t %x %x %x %x\n", tl->_1, tl->_2, tl->_3, tl->_4);

    if (tl->_1 == pBuffer[0] && tl->_2 == pBuffer[1] &&
    tl->_3 == pBuffer[2] && tl->_4 == pBuffer[3])
    bResult = true;

    return bResult;

    C / C++ / MFC help

  • proper conversion of unsigned char [16] -> unsigned long [4] [modified]
    S saiyuk6 7

    do you happen to know how i can fix it? i am lost

    C / C++ / MFC help

  • proper conversion of unsigned char [16] -> unsigned long [4] [modified]
    S saiyuk6 7

    BLE 2 f12b0ed9 782fae18 a87960ac f37b342e

    is passed into VerifyBuffer, but when it is decrypted it doesnt match BLE 1 b0c66fb8 733df651 4c2d26de a9a0e334 when i pass a MD5 comparision from unsigned char *pSignature hope that makes sense? it seems to lose data some how, not sure

    C / C++ / MFC help

  • proper conversion of unsigned char [16] -> unsigned long [4] [modified]
    S saiyuk6 7

    well it would be total 8 blocks for both _1 and _2, because a unsigned long is 4 bytes i am using Paul Kocher Blowfish Algorithm http://www.schneier.com/code/bfsh-koc.zip[^]

    C / C++ / MFC help

  • proper conversion of unsigned char [16] -> unsigned long [4] [modified]
    S saiyuk6 7

    I am stuck actually, im trying to write a md5 / blowfish function im not sure if i am correctly converting the MD5[16] buffer into a unsigned long[4] this doesnt really make too much sense too me

    typedef struct _tag2Long {
    unsigned long _1;
    unsigned long _2;
    unsigned long _3;
    unsigned long _4;
    } _2LONG;

    void SignBuffer(unsigned char *pbzKey, unsigned char *pbzBuffer,
    unsigned int iSize, unsigned long pSignature[4])
    {
    MD5_CTX md5;
    BLOWFISH_CTX bf;

    MD5Init(&md5);
    MD5Update(&md5, pbzBuffer, iSize);
    MD5Final(&md5);

    _2LONG *tl = (_2LONG*) md5.digest;

    printf("BLE 1\t\t %x %x %x %x\n", tl->_1, tl->_2, tl->_3, tl->_4);

    Blowfish_Init(&bf, pbzKey, 16);
    Blowfish_Encrypt(&bf, &tl->_1, &tl->_2);
    Blowfish_Encrypt(&bf, &tl->_3, &tl->_4);

    pSignature[0] = tl->_1;
    pSignature[1] = tl->_2;
    pSignature[2] = tl->_3;
    pSignature[3] = tl->_4;

    printf("BLE 2\t\t %x %x %x %x\n", pSignature[0], pSignature[1],
    pSignature[2], pSignature[3]);
    }

    bool VerifyBuffer(unsigned char *pbzKey, unsigned char *pSignature,
    unsigned int iSize, unsigned long pBuffer[4])
    {
    BLOWFISH_CTX bf;
    MD5_CTX md5;
    bool bResult = false;

    printf("BLD 1\t\t %x %x %x %x\n", pBuffer[0], pBuffer[1],
    pBuffer[2], pBuffer[3]);

    Blowfish_Init(&bf, pbzKey, 16);
    Blowfish_Decrypt(&bf, &pBuffer[0], &pBuffer[1]);
    Blowfish_Decrypt(&bf, &pBuffer[2], &pBuffer[3]);

    printf("BLD 2\t\t %x %x %x %x\n", pBuffer[0], pBuffer[1],
    pBuffer[2], pBuffer[3]);

    MD5Init(&md5);
    MD5Update(&md5, pSignature, iSize);
    MD5Final(&md5);

    _2LONG *tl = (_2LONG*) md5.digest;
    // printf("BLD 3\t\t %x %x %x %x\n", tl->_1, tl->_2, tl->_3, tl->_4);

    if (tl->_1 == pBuffer[0] && tl->_2 == pBuffer[1] &&
    tl->_3 == pBuffer[2] && tl->_4 == pBuffer[4])
    bResult = true;

    return bResult;
    }

    void main(void)
    {
    unsigned char bszBuffer[2] = {'A', 'B'};
    unsigned long ulSig[4];
    SignBuffer((unsigned char*)"key", bszBuffer, 2, ulSig);
    printf("\n");
    if (VerifyBuffer((unsigned char*)"key", bszBuffer, 2, ulSig))
    printf("\nok");
    else printf("\nerr");
    }

    and this is the output of them

    BLE 1 b0c66fb8 733df651 4c2d26de a9a0e334
    BLE 2 f12b0ed9 782fae18

    C / C++ / MFC help

  • POINT Draw Export/Code
    S saiyuk6 7

    Well i was thinking of more of a drawing tool, or somewhat that could convert it into POINT locations instead? so you could use Polyline, to draw out the item.. Microsoft example uses POINT aptHexagon[7] = {50,2, 93,25, 93,75, 50,98, 7,75, 7,25, 50,2}; but the Hexagon is way too big, editing it manualy takes alot of time to make it smaller because you would have to recompile to see if lines match up

    C / C++ / MFC json

  • POINT Draw Export/Code
    S saiyuk6 7

    Is there a application that can export Line Drawings, into POINT = {4,5,10,12...} struct arrays.. to be used with API calls like Polyline(...)

    C / C++ / MFC json
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups