Base64学习

Base64学习记录 Base64只是一个固定的转码,不安全的,是完全不安全的,只是将内容不能使肉眼辨认内容而已 String str="测试数据"; //转码Base64 Stringencode=Base64.getEncoder().encodeToString(str.getBytes()); System.out.println(encode); //解码Base64 byte[] decode = Base64.ge. 阅读详情

Base64学习


(图片来自
https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001431954588961d6b6f51000ca4279a3415ce14ed9d709000)

b1、b2、b3代表普通的字符串,如”a”,”b”,”c”
n1、n2、n3、n4代表用Base64编码后的字符
“abc” -> “YWJj”
图中可以看到,普通的字符是8个bit,Base64字符是6个bit

对字符串进行Base64编码:
  • 1、把待编码的字符串转换成二进制字符串 binStr
  • 2、末位加0使得binStr.length能被6整除(Base64字符每个字符对应6个bit)
  • 3、每6个bit组成unitBinStr 将unitBinStr转成int,从Base64表中取出对应字符并拼接
  • 4、拼接完后的Base64字符串,如果长度不能被4整除,末位补=
private val codeStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxzy0123456789+/"
private fun encodeBase64(string: String): String {
    //1、将待编码的字符串的每个字符转成二进制,不足8位高位补0,拼接起来
    var str = str2BinaryStr(string)
    var remainder = 0
    if (str.length % 6 != 0) {
        //2、一个Base64字符包含6个bit,不足6个的末位补0
        remainder = 6 - (str.length % 6)
        str += createZero(remainder)
        //println(str)
    }
    val result = StringBuilder()
    //3、6个bit一组,进行Base64字符转换
    for (i in 0 until str.length step 6) {
        if (i >= (str.length - remainder)) break
        val item = str.substring(i, i + 6)
        // 4、把二进制字符转成对应的整数
        val tenCode = item.toInt(2)
        //println(tenCode)
        //5、从Base64表中取出整数对应的Base64字符
        result.append(codeStr[tenCode])
    }
    //6、校验Base64字符串的长度是否是4的倍数,不是,末位补=
    val groupRemainder = (str.length / 6) % 4
    if (groupRemainder != 0) {
        result.append(createEqual(4 - groupRemainder))
    }
    return result.toString()
}
将Base64字符串解码:
private fun decodeBase64(string: String): String {
    //1、去掉末位=号
    val str = string.filter { it != '=' }
    var intNum = -1
    var oldBinaryStr = ""
    var decodeString = ""
    //2、得到原始的二进制字符串(有可能末位补过0)
    str.forEach {
        //从Base64表中取出Base64对应的index
        intNum = codeStr.indexOf(it)
        //将index转成二进制
        var binStr = intNum.toString(2)
        //注意这里是不足6补0而不是不足8 因为Base64每个字符对应6个bit
        if (binStr.length < 6) {
            binStr = createZero(6 - binStr.length) + binStr
        }
        //拼接成原始的二进制字符串(有可能末位补过0)
        oldBinaryStr += binStr
    }
    //3、去掉末位补的0
    val tail = oldBinaryStr.length % 6
    if (tail != 0) {
        oldBinaryStr = oldBinaryStr.substring(0, oldBinaryStr.length - (6 - tail))
    }
    //4、8个bit一组得到原始字符串
    for (i in 0..oldBinaryStr.length step 8) {
        if (i >= (oldBinaryStr.length - tail)) break
        val oldInt = oldBinaryStr.substring(i, i + 8).toInt(2)
        decodeString += oldInt.toChar()
    }
    //println(decodeString)
    return decodeString
}
其他辅助函数:
fun Char.getBinary(): String {
    val value = this.toInt()
    var quotient = value
    var remainder = 0
    val result = StringBuilder()
    while (quotient > 0) {
        remainder = quotient % 2
        quotient /= 2
        result.append(remainder)
    }
    return result.reverse().toString()
}
fun createZero(count: Int): String {
    if (count == 0) {
        return ""
    }
    val sb = StringBuilder()
    for (i in 0 until count) {
        sb.append("0")
    }
    return sb.toString()
}
fun createEqual(count: Int): String {
    if (count == 0) {
        return ""
    }
    val sb = StringBuilder()
    for (i in 0 until count) {
        sb.append("=")
    }
    return sb.toString()
}

抖音用户主页视频数据爬虫详解(点赞,收藏,分享等) 的包中有个max_cursor参数,请求载荷中也有一个这样的参数,每次请求的数据中max_cursor是下一个请求的载荷,,,同时has_more为1时候代表还能请求,0为不能请求,我们做如下判断。最后发现cookie很容易过期,批量爬取有点困难,,,,我们采用drissoinpage进行自动化获取。首先进行抓包分析,,,随便找个主页,f12,关键词搜索,发现这个包是以post开头。请你第一次运行先按0,进行登录(或者触发反爬的时候),登录完成之后,按1进行爬取,完整代码请在知识星球。 阅读详情

相关推荐

第十九届全国大学生智能车竞赛越野信标 硬件篇

全国大学生智能汽车竞赛,越野信标组

2301_77568650的博客 4115

【拓展】868- 一文读懂base64

一、为什么要使用 base64我们知道一个字节可表示的范围是 0 ~ 255(十六进制:0x00 ~ 0xFF), 其中 ASCII 值的范围为 0 ~ 127(十六进制:0x00 ~ 0...

pingan8787 1612

Android Profiler实战:如何用CPU分析工具揪出卡顿元凶(附线程状态解读)

本文深入解析Android Profiler中的CPU分析工具,重点聚焦线程活动监控。通过解读线程状态时间轴上的绿、黄、灰三色含义,并结合实战案例,指导开发者精准定位导致界面卡顿的CPU密集型或I/O阻塞代码,有效提升应用性能与用户体验。

weixin_29197699的博客 372

base64编码解码

base64编码解码

火红色祥云 4万+

问题:dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)

 1. 问题:Ubuntu安装软件的过程中出现依赖项的问题 “E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).” 按照指示执行如下两条命令都没有解决问题。 sudo apt-get -f install sudo apt-get --fix-broken ...

gloria_littlechi的博客 2万+

Windows应急响应实战:灰鸽子木马检测与清除全流程解析

远程控制木马(RAT)是一种基于客户端/服务器(C/S)架构的恶意软件,攻击者通过它能够远程操控受害主机,实现屏幕监控、文件窃取、键盘记录等操作,对个人隐私与企业数据安全构成严重威胁。其技术原理通常涉及进程注入、网络通信、持久化机制等核心环节,在应急响应中具有极高的分析价值。掌握此类木马的检测与清除方法,是Windows系统安全防护与事件处置的基本功。本文以经典的灰鸽子木马为例,结合进程分析、网络排查、注册表检查等实战技术,系统讲解从行为识别、痕迹取证到彻底清除的完整操作流程,并涵盖Rootkit对抗、无文

weixin_30521161的博客 414

什么是Base64算法?——全网最详细讲解

什么是Base64算法? 一、何为Base64算法 Base64是一种基于64个可打印字符来表示二进制数据的表示方法。由于,所以每6个比特为一个单元,对应某个可打印字符。3个字节有24个比特,对应于4个Base64单元,即3个字节可由4个可打印字符来表示。它可用来作为电子邮件的传输编码。在Base64中的可打印字符包括字母A...

扬俊的小屋 5万+

时频分析之STFT:短时傅里叶变换的原理与代码实现(非调用Matlab API)

STFT function [STFT, f, t] = mystft(x, win, hop, nfft, fs) % function: [STFT, f, t] = stft(x, win, hop, nfft, fs) % % Input: % x - signal in the time domain % win - analysis window function % hop - hop size % nfft - numb

frostime的博客 13万+

Base64简介

Base64简介 原文链接: https://blog.youkuaiyun.com/fengbingchun/article/details/85016088?ops_request_misc=&request_id=&biz_id=102&utm_term=base64&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduweb~default-0-85016088.pc_search_result_con

宁静致远的博客 1万+

HR效率翻倍!用Dify+飞书AI表格打造自动化简历处理流水线(附完整代码)

本文详细介绍了如何利用Dify工作流和飞书多维表格构建自动化简历处理系统,实现简历上传、AI智能解析与结构化数据入库的全流程自动化。通过整合大语言模型进行信息抽取,该系统能显著提升HR处理简历的效率与准确性,将HR从重复劳动中解放出来。

1a2s3d4f5g的博客 1025

【Altium designer】BOM导出 Bill of Materials 如何自定义格式

【Altium designer】如何自定义BOM导出格式 我们用Excel做一个xx.xlt的2003的模版文件,取文件名为:AltiumDesiger PCB BOM Template.xlt 将AltiumDesiger PCB BOM Template.xlt文件存放在:AltiumDesiger 安装目录的Template文件夹内

夜半少年的博客 2717

Base64编码详解

Base64 是一种将二进制数据转换为 ASCII 字符串格式的编码方式。它广泛应用于需要在文本协议(如电子邮件、HTTP 请求)中传输二进制数据的场景。

跟佟格湾一起学习计算机知识吧~ 9397

32位快速加法器设计

32位快速加法器设计

好好学习,天天向上 3289

C++学习之秘钥协商-base64

C++学习之秘钥协商-base64

qq_27302885的博客 1063

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

base64编码的学习和理解

编码表如下: 详细请学习:https://en.wikipedia.org/wiki/Base64

ningyanggege的博客 255

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

python学习之——tornado 传递base64图像

server.py class Pred(web.RequestHandler): def post(self): try: body_dic = json.loads(self.request.body.decode('utf-8')) imgb64 = body_dic.get("img_b64", None) buf_str = base64.b64decode(imgb64)

小米mm修仙路 696

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Base64的学习

来源 再一次看比如的代码的时候发现别人的图标是一串很长的字符串,而不是路径引用,从而开启了我对Base64的学习 解决 原生的atob和btoa方法进行Base64的编码 atob:解码 从a(base64) 到 b(lob) 的写法 btoa:编码 从 b(lob) 到 a(base64) 的写法 问题 那么我们如何再页面中使用Base64转义过的SVN图片呢? 1.直接用在线...

qq_39148344的博客 1093

Base64 编码学习

base64编码 在参数传输的过程中使用全英文的没问题,但一旦涉及到中文就可能会出现乱码情况。 与此类似,网络上传输的字符并不全是可打印的字符,比如二进制文件、图片,Base64的出现就是为了解决此问题。 Base64可以成为密码学的基石。 Base64编码具有不可读性,需要解码后才能阅读。 比如平时下载东西时有一个下载链接,在浏览器上是打不开的,但是在迅雷一类的下载软件上可以打开,这个链接就进行了 Base64编码,可能还加入了一些其他的加密方式。 base64编码是把 64个基本的ASCII码字符对数据

Goodric的博客 1593

mbedtls之base64算法的学习

Recently, I have been looking at the differences between the processing of base64 encode and decode by RTOS nuttx and mbedtls. Here is the processing of base64 algorithm by mbedtls. static const unsig...

天使之翼 4853

编码学习之Base64

Base64编码方式简介 我们直接用文本编辑器去打开pdf,exe等,肯定会看到很多乱码,因为并不是所有的二进制字符都可以打印出来。 为了能够打印出来所有的二进制数据,就用到了Base64编码。 Base64编码中,以每6个bit为一个单元,所以一共可以取64个值,对应64个可打印字符。这样3个Byte就相当于24bit,对应4个Base64单元。 例如编码Man,转化为Base64的编码就是 文本 M a n ASCII编码 77 97 110 二进制

柚子君的博客 659

Base64算法学习与理解

1.base64是加密算法吗? 加密:把明文变成一种不可破解的密文,提高识别度 编码:换一种体现形式,以便于传输,提高可读性 所有Base64不是加密算法 2.什么情况下用base64? URL特殊字符,转码,转义 嵌入图片src = “base64编码后的内容” 语言文字,底层都用二进制存储的 3.描述base64的算法原理 Base64,就是使用64个可打印字符来表示二进制数据的方法 为什么是...

热心市民小王的博客 177

Base64 编码 学习

Base64是一种用64个字符来表示任意二进制数据的方法。 用记事本打开exe、jpg、pdf这些文件时,我们都会看到一大堆乱码,因为二进制文件包含很多无法显示和打印的字符,所以,如果要让记事本这样的文本处理软件能处理二进制数据,就需要一个二进制到字符串的转换方法。Base64是一种最常见的二进制编码方法。 Base64的原理很简单,首先,准备一个包含64个字符的数组: ['A',

CSUCFL的专栏 1379

Base64编码学习

一、Base64的由来 在参数传输的过程中经常遇到的一种情况:使用全英文的没问题,但一旦涉及到中文就会出现乱码情况。与此类似,网络上传输的字符并不全是可打印的字符,比如二进制文件、图片等。Base64的出现就是为了解决此问题,它是基于64个可打印的字符来表示二进制的数据的一种方法。 电子邮件刚问世的时候,只能传输英文,但后来随着用户的增加,中文、日文等文字的用户也有需求,但这些字符并不能被服务...

星的奏鸣曲 230
上一篇: Toolbar修改右边的三个点
下一篇: Android Lifecyle
普通网友
博客等级 码龄12年 7粉丝 13原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值