openssl AES encrypt (AES_ctr128_encrypt)

Programming/C,CPP,CS 2016. 9. 19. 08:50 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

openssl AES encrypt (AES_ctr128_encrypt)



Sample Class













AESCTR.cppAESCTR.h


336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

성동구 인근 지역 프로그래밍 과외 합니다.


지역 : 서울 성동구 인근


종목 : 프로그래밍, 정보올림피아드, CCNA, CCNP


경력 : 지도학생) 2013 초등부 정보올림피아드 전국대회 은상 수상

        지도학생) 정보올림피아드 본선 진출 다수


         전) 서울 서울특별시립종합직업전문학교 외부강사

         전) 천안 그린컴퓨터학원 프로그래밍 강사

         전) 한국기술교육대학교 대학원 컴퓨터공학부 박사과정 수료

         전) 청주 그린컴퓨터학원 프로그래밍 강사

         전) 아산소재 대학교 시간강사

         전) 천안소재 대학교 시간강사



         현) 한국기술교육대학교 평생능력개발 이러닝 운영강사

         현) IT기업 연구소 재직중




자세한 문의는


tansanc23@gmail.com 으로 문의해 주세요.

공일공-구구육이-일사일칠



C++ Standard library has many containers

Programming/C,CPP,CS 2016. 7. 19. 10:37 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

C++ Standard library has many containers. Depending on situation you have to choose one which best suits your purpose. It is not possible for me to talk about each of them. But here is the chart that helps a lot (source):






C++ 스탠다드 라이브러리에 많은 컨테이너 들이 있다.
흔히 사용하는 List, Stack, Vector 뿐만 아니라 다양한 컨테이너들이 존재하는데, 그 컨테이너들을 언제 사용해야 할지를 FlowChart 를 따라가면서 쉽게 선택할 수 있다. 
















enter image description here




c, cpp, com, atl, stl, vc7 String

Programming/C,CPP,CS 2016. 3. 28. 10:14 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.


. C 자료형

    char (1) , short (2) , int (4) , long (4), float (4) , double (8) , bool 

    문자 : char

    char szName[20] = "kim";


 

2. WIN API 자료형

 

    BYTE (1,unsigned char) , WORD (2,unsigned short) , UNIT (4, unsigned int) , 

    DWORD (4,unsigned long) , LONG (4,long) , BOOL

    문자 : UCHAR (unsigned char)

    핸들 : 대상을 구분하는 4바이트 정수(HWND, HDC 등)

 

    MBCS문자(열)                 유니코드문자(열)           자동매크로문자(열)

    char                                     wchar_t                              TCHAR

    LPSTR(char*)                    LPWSTR(wchar_t*)        LPTSTR

    LPCSTR(const char*)      LPCWSTR                         LPCTSTR

 

    (참조1) 문자열에 대해 그냥 습관적으로 LPTSTR 또는 LPCTSTR 를 써라

    (참조2) 헝가리안명명법 

                   w(WORD) , dw(DWORD) , i(int) , b(BOOL) , ch(문자) , sz(문자열) , h(핸들)

                   cb(바이트수) , a(배열)

 (참조3) OLECHAR(wchar_t), LPOLESTR(LPWSTR), LPCOLESTR(LPCWSTR), OLESTR(x) = _T(x)


 

3. COM 스트링


    BSTR : 문자열길이를 시작전에 저장하고, 이어서 유니코드문자열을 저장하는 방식
                  1> LPCWSTR ->  BSTR : 생성안됨. 생성함수를 이용해야함
                               BSTR bstr = sysAllocString(L"Hi Bob"); // 메모리할당

                              sysFreeString(bstr); // 메모리제거

                  2> BSTR  ->  LPCWSTR : 형변환 가능

 

    VARIANT : 문자열이 들어올때  BSTR과 동일

 

4. CRT(c runtime library) 지원 스트링클래스

 

    _bstr_t : BSTR랩퍼클래스, 메모리할당/제거를 자동으로 수행

                  1> LPCSTR, LPCWSTR  -> _bstr_t 
                               _bstr_t bs1 = "char string";  // 생성

                  2> _bstr_t  ->  LPCSTR, LPCWSTR 
                               LPCSTR psz1 = (LPCSTR)bs1; // 형변환

                  3> _bstr_t  ->  BSTR : 형변환안됨함수이용
                               BSTR bstr = bs1.copy();

                               sysFreeString(bstr);  // BSTR은 사용후 메모리해제를 해야하는 불편이있음..

 

    _variant_t : VARIANT랩퍼클래스, 메모리할당/제거를 자동으로 수행

                  1> LPCSTR, LPCWSTR  -> _variant_t 
                               _variant_t v1 = "char string"; // 생성

                  2> _variant_t  -> _bstr_t  ->  LPCSTR, LPCWSTR 
                               LPCSTR psz1 = (LPCSTR)(_bstr_t)v1;  //형변환

 

5. ATL 지원 스트링클래스

 

    CComBSTR : BSTR랩퍼클래스, 메모리할당/제거를 자동으로 수행

                  1> LPCSTR, LPCWSTR  ->  CComBSTR 

                               CComBSTR bs1 = "char string"; // 생성

                  2> CComBSTR  ->  BSTR   -> LPCWSTR

                               BSTR bstr = (BSTR)bs1;  // 형변환

 

                  (참조) BSTR -> CComBSTR 

                               CComBSTR bs2; bs2.Attach(W2BSTR(L"Bob"))

                              

    CComVariant : VARIANT랩퍼클래스, 메모리할당/제거를 자동으로 수행

                  1> LPCSTR, LPCWSTR  ->  CComVariant 

                               CComVariant bs1 = "char string"; // 생성

                  2> CComVariant  ->  CComBSTR   ->  BSTR   -> LPCWSTR

                               CComBSTR bs2 = bs1.bstrVal;

 

6. STL 스트링

 

    string 

                  1> LPCSTR -> string

                                string  str = "char string"; //생성

                  2> string -> LPCSTR : 형변환 안됨. 함수이용 

                                LPCSTR psz = str.c_str();

    wstring

                   1> LPCWSTR -> wstring

                                wstring  str = "wide char string"; //생성

                  2> wstring -> LPCWSTR : 형변환 안됨. 함수이용 

                                LPCWSTR psz = str.c_str();

 

7. MFC 스트링

 

    CString

                  1> LPCSTR, LPCWSTR  ->  CString 

                                CString  str = "char string"; //생성

                  2> CString  -> LPCTSTR :

                                LPCTSTR  lpsz = (LPCTSTR)str; //형변환

 

                  (참고)  CString  -> LPTSTR :  함수이용

                               LPTSTR lptsz  = str.GetBuffer(0); str.ReleaseBuffer(); //  올바른 사용

                               LPTSTR lptsz  = (LPTSTR)(LPCTSTR)str  //  잘못된 사용

                               CString  -> BSTR  

                               BSTR bstr = str.AllocSysString(); sysFreeString(bstr)

 

8. VC7 스트링

 

    String : .NET에서 새로 정의한 스트링 클래스

                               String* s1 = S"this is nice"; // 생성

                               CString s2(s1); // 형변환


출처 : http://hacheo.egloos.com/3891296


Winpcap Test 01

Programming/C,CPP,CS 2016. 3. 7. 08:50 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Winpcap Test 01



Download WinPcap 4.1.2 Developer's Pack

http://www.winpcap.org/devel.htm



C/C++ -> Genenral -> Additional Include Directories : WpdPack/WpdPack/Include


Linker -> General -> Additional Library Directories : WpdPack/WpdPack/Lib


Linker -> Input -> Addtional Dependencies : wpcap.lib Packet.lib


C/C++ -> Preprocessor -> PreProcessor Definitions : HAVE_REMOTE


sample Code

/* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)

 * Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)

 * All rights reserved.

 *

 * Redistribution and use in source and binary forms, with or without

 * modification, are permitted provided that the following conditions

 * are met:

 *

 * 1. Redistributions of source code must retain the above copyright

 * notice, this list of conditions and the following disclaimer.

 * 2. Redistributions in binary form must reproduce the above copyright

 * notice, this list of conditions and the following disclaimer in the

 * documentation and/or other materials provided with the distribution.

 * 3. Neither the name of the Politecnico di Torino, CACE Technologies 

 * nor the names of its contributors may be used to endorse or promote 

 * products derived from this software without specific prior written 

 * permission.

 *

 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT

 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR

 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT

 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,

 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT

 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,

 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY

 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

 *

 */



#include <stdlib.h>

#include <stdio.h>


//

// NOTE: remember to include WPCAP and HAVE_REMOTE among your

// preprocessor definitions.

//


#include <pcap.h>


#define LINE_LEN 16


int main(int argc, char **argv)

{   

pcap_if_t *alldevs, *d;

pcap_t *fp;

u_int inum, i=0;

char errbuf[PCAP_ERRBUF_SIZE];

int res;

struct pcap_pkthdr *header;

const u_char *pkt_data;


    printf("pktdump_ex: prints the packets of the network using WinPcap.\n");

    printf("   Usage: pktdump_ex [-s source]\n\n"

           "   Examples:\n"

           "      pktdump_ex -s file://c:/temp/file.acp\n"

           "      pktdump_ex -s rpcap://\\Device\\NPF_{C8736017-F3C3-4373-94AC-9A34B7DAD998}\n\n");


    if(argc < 3)

    {


        printf("\nNo adapter selected: printing the device list:\n");

        /* The user didn't provide a packet source: Retrieve the local device list */

        if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)

        {

            fprintf(stderr,"Error in pcap_findalldevs_ex: %s\n", errbuf);

            return -1;

        }

        

        /* Print the list */

        for(d=alldevs; d; d=d->next)

        {

            printf("%d. %s\n    ", ++i, d->name);


            if (d->description)

                printf(" (%s)\n", d->description);

            else

                printf(" (No description available)\n");

        }

        

        if (i==0)

        {

            fprintf(stderr,"No interfaces found! Exiting.\n");

            return -1;

        }

        

        printf("Enter the interface number (1-%d):",i);

        scanf_s("%d", &inum);

        

        if (inum < 1 || inum > i)

        {

            printf("\nInterface number out of range.\n");


            /* Free the device list */

            pcap_freealldevs(alldevs);

            return -1;

        }

        

        /* Jump to the selected adapter */

        for (d=alldevs, i=0; i< inum-1 ;d=d->next, i++);

        

        /* Open the device */

        if ( (fp= pcap_open(d->name,

                            100 /*snaplen*/,

                            PCAP_OPENFLAG_PROMISCUOUS /*flags*/,

                            20 /*read timeout*/,

                            NULL /* remote authentication */,

                            errbuf)

                            ) == NULL)

        {

            fprintf(stderr,"\nError opening adapter\n");

            return -1;

        }

    }

    else 

    {

        // Do not check for the switch type ('-s')

        if ( (fp= pcap_open(argv[2],

                            100 /*snaplen*/,

                            PCAP_OPENFLAG_PROMISCUOUS /*flags*/,

                            20 /*read timeout*/,

                            NULL /* remote authentication */,

                            errbuf)

                            ) == NULL)

        {

            fprintf(stderr,"\nError opening source: %s\n", errbuf);

            return -1;

        }

    }


    /* Read the packets */

    while((res = pcap_next_ex( fp, &header, &pkt_data)) >= 0)

    {


        if(res == 0)

            /* Timeout elapsed */

            continue;


        /* print pkt timestamp and pkt len */

        printf("%ld:%ld (%ld)\n", header->ts.tv_sec, header->ts.tv_usec, header->len);          

        

        /* Print the packet */

        for (i=1; (i < header->caplen + 1 ) ; i++)

        {

            printf("%.2x ", pkt_data[i-1]);

            if ( (i % LINE_LEN) == 0) printf("\n");

        }

        

        printf("\n\n");     

    }


    if(res == -1)

    {

        fprintf(stderr, "Error reading the packets: %s\n", pcap_geterr(fp));

        return -1;

    }


    return 0;

}


'Programming > C,CPP,CS' 카테고리의 다른 글

Winpcap Test 03  (0) 2016.03.07
Winpcap Test 02  (0) 2016.03.07
CPP 2015-01-15 수업내용 정리  (0) 2015.01.15
C 2015-01-09 실습  (0) 2015.01.09
Run-Time Check Failure #3 - The variable 'a' is being used without being initialized.  (0) 2014.05.14
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

지역 : 천안, 아산, 청주


종목 : 프로그래밍, 정보올림피아드, CCNA, CCNP


경력 : 지도학생) 2013 초등부 정보올림피아드 전국대회 은상 수상

         전) 서울 서울특별시립종합직업전문학교 외부강사

         전) 천안 그린컴퓨터학원 프로그래밍 강사


         현) 청주 그린컴퓨터학원 프로그래밍 강사

         현) 아산소재 대학교 시간강사

         현) 천안소재 대학교 시간강사

         현) 대학원 박사과정 재학중




자세한 문의는


tansanc23@gmail.com 으로 문의해 주세요.

공일공-구구육이-일사일칠



336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

#include <stdio.h>

 

int main(void)

{

        int a;

        printf("%d", a);

        return 0;

}

 




Run-Time Check Failure #3 - The variable 'a' is being used without being initialized.


이 에러는 a 라는 변수가 초기화 없이 사용되었다고 나는 에러로


a 라는 변수에는 아무 값도 저장 되지 않은 상태이므로


a 라는 변수를 연산에 사용하거나 출력하면 a 라는 값이 무슨 값일지 모르니까 문제가 된다.

( 출력 내용을 예상 할 수 있겠는가? )


a 에 어떤 값은 저장시킨 다음 사용하면 문제가 없다.



'Programming > C,CPP,CS' 카테고리의 다른 글

CPP 2015-01-15 수업내용 정리  (0) 2015.01.15
C 2015-01-09 실습  (0) 2015.01.09
C 언어 방향키 입력활용  (0) 2014.05.03
cpp  (0) 2014.05.03
C 정렬함수 인자 주소값, 사이즈  (0) 2014.04.12

C 배열 연습문제

실습과제 모음 2014. 4. 13. 14:46 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

C 배열 연습문제


1.     정수형 5개를 저장하는 배열을 임의의 수로 초기화하고 배열을 정렬하라.

2.     정수형 5개를 저장하는 배열을 임의의 수로 초기화하고 배열이 평균, 분산, 표준편차를 구하라

3.     정수형 5개를 저장하는 배열을 임의의 수로 초기화하고 배열 요소의 최소값을 출력하라.

4.     정수형 5개를 저장하는 배열을 임의의 수로 초기화하고 배열 요소의 중간값을 출력하라.

5.     정수형 5개를 저장하는 배열을 임의의 수로 초기화하고 배열 요소 두 개를 합하여 만들 수 있는 모든 값을 출력하시오. (중복 제거)

Ex) { 1 , 2, 3, 2, 1}
1+1 1+2 1+3 2+2 2+3
결과 : 2 3 4 5

6.     정수형 5개를 저장하는 배열을 임의의 수로 초기화하고 배열 요소 중 소수(Prime Number)의 개수를 출력하시오.

7.     정수형 5개를 저장하는 배열을 한자리 임의의 수로 초기화하고 배열 요소 중 각 숫자가 몇 번 나오는 지를 출력하라.

Ex) { 2, 2, 3, 1, 2 }

1 : 1

2 : 3

3 : 1

 


C 배열 실습문제.docx


'실습과제 모음' 카테고리의 다른 글

CPP 문자열 클래스 실습  (0) 2014.04.26
studentInfo 실습  (1) 2014.04.19
C 언어 달력 소스코드  (0) 2014.04.05
C 배열 실습 10명 성적처리  (0) 2014.04.05
별 찍기 예제 #3  (0) 2014.03.29

C 선택, 버블 정렬 함수

Programming/C,CPP,CS 2014. 4. 12. 15:53 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

선택 정렬 ========

void sortArr(int *x)

{

    int smaller;

    int smallIndex;

    int temp, i, j;

 

    for( j = 0 ; j < 5 - 1 ; j++ )

    {

        smaller = x[j];

        smallIndex = j;

        for( i = j+1; i < 5 ; i++)

        {

            if ( smaller > x[i] )

            {

                smaller = x[i];     smallIndex = i;

            }

        }

        temp = x[j];

        x[j] = x[smallIndex];

        x[smallIndex] = temp;

    }

}

버블 정렬 ===============

 

void sortArr(int *x)

{

    int i, temp, j;

    for(j = 1; j < 5 ; j++)

    {

        for( i = 0 ; i < 5-j ; i++ )

        {

            if ( x[i] > x[i+1] )

            {

                temp = x[i];

                x[i] = x[i+1];

                x[i+1] = temp;

            }

        }

    }

}

'Programming > C,CPP,CS' 카테고리의 다른 글

cpp  (0) 2014.05.03
C 정렬함수 인자 주소값, 사이즈  (0) 2014.04.12
C 언어 반복문 실습 과제  (0) 2014.03.22
CPP 객체지향 핵심이롬  (0) 2014.03.09
아두이노와 연계한 CPP 시리얼 통신 응용  (0) 2014.03.08

C 언어 달력 소스코드

실습과제 모음 2014. 4. 5. 15:09 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

#include <stdio.h>

 

int isLeapYear(int year);

int totalDaysYearMonth(int year, int month);

// year : 년도month : 월을입력하면그년도그월의총일수가

// 반환된다.

int totalDaysYear(int year);

int firstDayOfYear(int year);

 

int DayOfWeekYearMonth(int year, int month);

// year : 년도month : 월을입력하면그년도그월의요일이

// 반환된다.

 

int main( )

{

    int year;

    int month;

    int i;

    int totalDay = 0;

    printf(",월을입력하시오:");

    scanf("%d,%d", &year, &month);

 

    printf("%d\n", DayOfWeekYearMonth(year, month));

 

    return 0;

}

 

int DayOfWeekYearMonth(int year, int month)

{

    int i;

    int totalDay = 0;

 

    totalDay = firstDayOfYear(year);

    for( i = 1 ; i < month ; i++)

    {

        totalDay += totalDaysYearMonth(year, i);

    }

    return totalDay % 7;

}

 

int firstDayOfYear(int year)

{

    int i;

    int totalDay = 0;

    for ( i = 1980 ; i < year ; i++ )

    {

        totalDay += totalDaysYear(i);

    }

    return totalDay % 7;

}

int totalDaysYear(int year)

{

    if( isLeapYear(year) )

    {

        return 366;

    }

    else

    {

        return 365;

    }

}

int totalDaysYearMonth(int year, int month)

{

 

    if( month == 1 || month == 3 ||

        month == 5 || month == 7 ||

        month == 8 || month == 10 ||

        month == 12 )

    {

        return 31;

    }

    else

    {

        if( month == 2 )

        {

            if( isLeapYear(year) )

            {

                return 29;

            }

            else

            {

                return 28;

            }

        }

        else

        {

            return 30;

        }

    }

}

int isLeapYear(int year)

{

    if( ( (year % 4 == 0 && year % 100 != 0) || year % 400 == 0) )

    {

        return 1;

    }

    else

    {

        return 0;

    }

}

'실습과제 모음' 카테고리의 다른 글

studentInfo 실습  (1) 2014.04.19
C 배열 연습문제  (0) 2014.04.13
C 배열 실습 10명 성적처리  (0) 2014.04.05
별 찍기 예제 #3  (0) 2014.03.29
별 찍기 예제 #2  (0) 2014.03.29