strencode.cpp

来自「MPICH是MPI的重要研究,提供了一系列的接口函数,为并行计算的实现提供了编程」· C++ 代码 · 共 64 行

CPP
64
字号
#include "mpdutil.h"#include <stdlib.h>#include <malloc.h>/* * This is not encryption. * This is simply encoding characters into number strings to * avoid string delimination problems. */char * EncodePassword(char *pwd){    int length;    int i;    int len;    char *pStr, *pRetVal;    if (pwd == NULL)	return NULL;    len = strlen(pwd);    length = len * 3;    for (i=0; i<len; i++)    {	if (pwd[i] > 99)	    length++;    }    length++; /* add one character for the NULL termination */    pRetVal = pStr = (char*)malloc(length);    if (pStr == NULL)	return NULL;    for (i=0; i<len; i++)    {	sprintf(pStr, ".%d", (int)pwd[i]);	pStr = &pStr[strlen(pStr)];    }    if (len == 0)	*pRetVal = '\0';    return pRetVal;}void DecodePassword(char *pwd){    char *pChar, *pStr;    if (pwd == NULL)	return;    pChar = pStr = pwd;    while (*pStr != '\0')    {	if (*pStr == '.')	    pStr++;	*pChar = (char)atoi(pStr);	pChar++;	while ((*pStr != '.') && (*pStr != '\0'))	    pStr++;    }    *pChar = '\0';}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?